debug: get rid of DBGC_MAX_FIXED
authorRalph Boehme <slow@samba.org>
Wed, 13 May 2015 14:03:38 +0000 (16:03 +0200)
committerGünther Deschner <gd@samba.org>
Wed, 1 Jul 2015 18:01:16 +0000 (20:01 +0200)
Simplify class table by using designated array initializers and
ARRAY_SIZE macro.

Signed-off-by: Ralph Boehme <slow@samba.org>
Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Guenther Deschner <gd@samba.org>
lib/util/debug.c
lib/util/debug.h

index dce32925e1f73b40cbe264ee51d4154d629f9d00..6b8fc0c4a81e0157366df529c70936fc8386f4f4 100644 (file)
@@ -416,11 +416,37 @@ static void debug_backends_log(const char *msg, int msg_level)
 */
 bool    override_logfile;
 
+static const char *default_classname_table[] = {
+       [DBGC_ALL] =            "all",
+       [DBGC_TDB] =            "tdb",
+       [DBGC_PRINTDRIVERS] =   "printdrivers",
+       [DBGC_LANMAN] =         "lanman",
+       [DBGC_SMB] =            "smb",
+       [DBGC_RPC_PARSE] =      "rpc_parse",
+       [DBGC_RPC_SRV] =        "rpc_srv",
+       [DBGC_RPC_CLI] =        "rpc_cli",
+       [DBGC_PASSDB] =         "passdb",
+       [DBGC_SAM] =            "sam",
+       [DBGC_AUTH] =           "auth",
+       [DBGC_WINBIND] =        "winbind",
+       [DBGC_VFS] =            "vfs",
+       [DBGC_IDMAP] =          "idmap",
+       [DBGC_QUOTA] =          "quota",
+       [DBGC_ACLS] =           "acls",
+       [DBGC_LOCKING] =        "locking",
+       [DBGC_MSDFS] =          "msdfs",
+       [DBGC_DMAPI] =          "dmapi",
+       [DBGC_REGISTRY] =       "registry",
+       [DBGC_SCAVENGER] =      "scavenger",
+       [DBGC_DNS] =            "dns",
+       [DBGC_LDB] =            "ldb",
+};
+
 /*
  * This is to allow reading of DEBUGLEVEL_CLASS before the debug
  * system has been initialized.
  */
-static const int debug_class_list_initial[DBGC_MAX_FIXED + 1];
+static const int debug_class_list_initial[ARRAY_SIZE(default_classname_table)];
 
 static int debug_num_classes = 0;
 int     *DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
@@ -460,32 +486,6 @@ static bool    log_overflow   = false;
  * white space. There must be one name for each DBGC_<class name>, and they
  * must be in the table in the order of DBGC_<class name>..
  */
-static const char *default_classname_table[] = {
-       "all",               /* DBGC_ALL; index refs traditional DEBUGLEVEL */
-       "tdb",               /* DBGC_TDB          */
-       "printdrivers",      /* DBGC_PRINTDRIVERS */
-       "lanman",            /* DBGC_LANMAN       */
-       "smb",               /* DBGC_SMB          */
-       "rpc_parse",         /* DBGC_RPC_PARSE    */
-       "rpc_srv",           /* DBGC_RPC_SRV      */
-       "rpc_cli",           /* DBGC_RPC_CLI      */
-       "passdb",            /* DBGC_PASSDB       */
-       "sam",               /* DBGC_SAM          */
-       "auth",              /* DBGC_AUTH         */
-       "winbind",           /* DBGC_WINBIND      */
-       "vfs",               /* DBGC_VFS          */
-       "idmap",             /* DBGC_IDMAP        */
-       "quota",             /* DBGC_QUOTA        */
-       "acls",              /* DBGC_ACLS         */
-       "locking",           /* DBGC_LOCKING      */
-       "msdfs",             /* DBGC_MSDFS        */
-       "dmapi",             /* DBGC_DMAPI        */
-       "registry",          /* DBGC_REGISTRY     */
-       "scavenger",         /* DBGC_SCAVENGER    */
-       "dns",               /* DBGC_DNS          */
-       "ldb",               /* DBGC_LDB          */
-       NULL
-};
 
 static char **classname_table = NULL;
 
@@ -744,8 +744,7 @@ Init debugging (one time stuff)
 
 static void debug_init(void)
 {
-       int i;
-       const char **p;
+       size_t i;
 
        if (state.initialized)
                return;
@@ -754,8 +753,8 @@ static void debug_init(void)
 
        debug_setup_talloc_log();
 
-       for(p = default_classname_table; *p; p++) {
-               debug_add_class(*p);
+       for (i = 0; i < ARRAY_SIZE(default_classname_table); i++) {
+               debug_add_class(default_classname_table[i]);
        }
 
        for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
index 8d8f43d417f3985b646f4cf96ea8adb4f98dccff..9baf762a045d35e5184ce452c92046a45da08796 100644 (file)
@@ -89,9 +89,6 @@ bool dbghdr( int level, const char *location, const char *func);
 #define DBGC_DNS               21
 #define DBGC_LDB               22
 
-/* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */
-#define DBGC_MAX_FIXED         22
-
 /* So you can define DBGC_CLASS before including debug.h */
 #ifndef DBGC_CLASS
 #define DBGC_CLASS            0     /* override as shown above */