]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
src: fix unused-but-set-variable compile warnings
authorVictor Julien <vjulien@oisf.net>
Mon, 16 Jan 2023 21:09:02 +0000 (22:09 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 24 Jan 2023 08:34:23 +0000 (09:34 +0100)
Tested on Fedora 37 with clang 15.

datasets.c:852:9: error: variable 'n' set but not used [-Werror,-Wunused-but-set-variable]
    int n = 0;
        ^
1 error generated.

(cherry picked from commit 1bc6976a061a78f953f6b9c796cd4135c1494beb)

src/datasets.c
src/detect-engine-build.c
src/detect-engine-enip.c
src/detect-engine-iponly.c
src/detect-engine-port.c
src/detect-engine-sigorder.c
src/flow-manager.c
src/output-json-ftp.c
src/util-device.c
src/util-reference-config.c

index 1ca7ca1b0b7a6933d9de57f2f94461aa31c5faed..b0dea2f304a881b4873233a6af84ccc1ae8778b2 100644 (file)
@@ -633,7 +633,6 @@ static void GetDefaultMemcap(uint64_t *memcap, uint32_t *hashsize)
 int DatasetsInit(void)
 {
     SCLogDebug("datasets start");
-    int n = 0;
     ConfNode *datasets = ConfGetNode("datasets");
     uint64_t default_memcap = 0;
     uint32_t default_hashsize = 0;
@@ -701,7 +700,7 @@ int DatasetsInit(void)
             char conf_str[1024];
             snprintf(conf_str, sizeof(conf_str), "datasets.%d.%s", list_pos, set_name);
 
-            SCLogDebug("(%d) set %s type %s. Conf %s", n, set_name, set_type->val, conf_str);
+            SCLogDebug("set %s type %s. Conf %s", set_name, set_type->val, conf_str);
 
             if (strcmp(set_type->val, "md5") == 0) {
                 Dataset *dset = DatasetGet(set_name, DATASET_TYPE_MD5, save, load,
@@ -709,9 +708,8 @@ int DatasetsInit(void)
                         hashsize > 0 ? hashsize : default_hashsize);
                 if (dset == NULL)
                     FatalError(SC_ERR_FATAL, "failed to setup dataset for %s", set_name);
-                SCLogDebug("dataset %s: id %d type %s", set_name, n, set_type->val);
+                SCLogDebug("dataset %s: id %u type %s", set_name, dset->id, set_type->val);
                 dset->from_yaml = true;
-                n++;
 
             } else if (strcmp(set_type->val, "sha256") == 0) {
                 Dataset *dset = DatasetGet(set_name, DATASET_TYPE_SHA256, save, load,
@@ -719,9 +717,8 @@ int DatasetsInit(void)
                         hashsize > 0 ? hashsize : default_hashsize);
                 if (dset == NULL)
                     FatalError(SC_ERR_FATAL, "failed to setup dataset for %s", set_name);
-                SCLogDebug("dataset %s: id %d type %s", set_name, n, set_type->val);
+                SCLogDebug("dataset %s: id %u type %s", set_name, dset->id, set_type->val);
                 dset->from_yaml = true;
-                n++;
 
             } else if (strcmp(set_type->val, "string") == 0) {
                 Dataset *dset = DatasetGet(set_name, DATASET_TYPE_STRING, save, load,
@@ -729,9 +726,8 @@ int DatasetsInit(void)
                         hashsize > 0 ? hashsize : default_hashsize);
                 if (dset == NULL)
                     FatalError(SC_ERR_FATAL, "failed to setup dataset for %s", set_name);
-                SCLogDebug("dataset %s: id %d type %s", set_name, n, set_type->val);
+                SCLogDebug("dataset %s: id %u type %s", set_name, dset->id, set_type->val);
                 dset->from_yaml = true;
-                n++;
             }
 
             list_pos++;
index 5901f9283d348c0a83ee05d56ebbea482697d36a..3c1d9acde3812a69f9f60e58ce7ef62947028dc1 100644 (file)
@@ -1652,8 +1652,6 @@ static void DetectEngineAddDecoderEventSig(DetectEngineCtx *de_ctx, Signature *s
  */
 int SigAddressPrepareStage2(DetectEngineCtx *de_ctx)
 {
-    uint32_t sigs = 0;
-
     SCLogDebug("building signature grouping structure, stage 2: "
             "building source address lists...");
 
@@ -1677,8 +1675,6 @@ int SigAddressPrepareStage2(DetectEngineCtx *de_ctx)
         if (s->init_data->init_flags & SIG_FLAG_INIT_DEONLY) {
             DetectEngineAddDecoderEventSig(de_ctx, s);
         }
-
-        sigs++;
     }
 
     IPOnlyPrepare(de_ctx);
index 3dcb681a82a553ccc3f8128636a78167320640f1..adc41557d5cc690d24320f369767683045a47308 100644 (file)
@@ -164,7 +164,9 @@ static int CIPPathMatch(CIPServiceEntry *svc, DetectCipServiceData *cipserviced)
 static int CIPServiceMatch(ENIPTransaction *enip_data,
         DetectCipServiceData *cipserviced)
 {
+#ifdef DEBUG
     int count = 1;
+#endif
     CIPServiceEntry *svc = NULL;
     //SCLogDebug("CIPServiceMatchAL");
     TAILQ_FOREACH(svc, &enip_data->service_list, next)
@@ -200,7 +202,9 @@ static int CIPServiceMatch(ENIPTransaction *enip_data,
                 return 1;
             }
         }
+#ifdef DEBUG
         count++;
+#endif
     }
     return 0;
 }
index e9604384a3900277ec98225b8d8e97e4247f4ebb..d06d28e06f4086d99b2aad34cf4aa69c59f60fa3 100644 (file)
@@ -448,8 +448,9 @@ static IPOnlyCIDRItem *IPOnlyCIDRItemInsert(IPOnlyCIDRItem *head,
 void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead)
 {
     SCEnter();
+#ifdef DEBUG
     uint32_t i = 0;
-
+#endif
     IPOnlyCIDRItem *it, *next = NULL;
 
     if (tmphead == NULL) {
@@ -461,8 +462,10 @@ void IPOnlyCIDRListFree(IPOnlyCIDRItem *tmphead)
     next = it->next;
 
     while (it != NULL) {
+#ifdef DEBUG
         i++;
         SCLogDebug("Item(%p) %"PRIu32" removed", it, i);
+#endif
         SCFree(it);
         it = next;
 
index 43a68f3256ef49171d14debc2211d1874b3a4c57..c5286886ac177123d3d90277b1a67854cf0c88df 100644 (file)
@@ -100,13 +100,16 @@ void DetectPortFree(const DetectEngineCtx *de_ctx, DetectPort *dp)
 void DetectPortPrintList(DetectPort *head)
 {
     DetectPort *cur;
+#ifdef DEBUG
     uint16_t cnt = 0;
-
+#endif
     SCLogDebug("= list start:");
     if (head != NULL) {
         for (cur = head; cur != NULL; cur = cur->next) {
              DetectPortPrint(cur);
+#ifdef DEBUG
              cnt++;
+#endif
         }
         SCLogDebug(" ");
     }
index 3c0c1e9697e5c68218e5b5f4694b27d159122338..8859ab16d0a53d40c7143506adf3a9372245219d 100644 (file)
@@ -730,8 +730,9 @@ void SCSigOrderSignatures(DetectEngineCtx *de_ctx)
     Signature *sig = NULL;
     SCSigSignatureWrapper *sigw = NULL;
     SCSigSignatureWrapper *sigw_list = NULL;
-
+#ifdef DEBUG
     int i = 0;
+#endif
     SCLogDebug("ordering signatures in memory");
 
     sig = de_ctx->sig_list;
@@ -742,7 +743,9 @@ void SCSigOrderSignatures(DetectEngineCtx *de_ctx)
         sigw_list = sigw;
 
         sig = sig->next;
+#ifdef DEBUG
         i++;
+#endif
     }
 
     /* Sort the list */
@@ -754,9 +757,13 @@ void SCSigOrderSignatures(DetectEngineCtx *de_ctx)
     /* Recreate the sig list in order */
     de_ctx->sig_list = NULL;
     sigw = sigw_list;
+#ifdef DEBUG
     i = 0;
+#endif
     while (sigw != NULL) {
+#ifdef DEBUG
         i++;
+#endif
         sigw->sig->next = NULL;
         if (de_ctx->sig_list == NULL) {
             /* First entry on the list */
index cdb611c07e5aa57d32e76e5b2238f8339403961f..bb1e720fcb311637bcaadba5f7cdac1b9a5c9557 100644 (file)
@@ -737,12 +737,12 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
     uint16_t flow_mgr_host_spare = StatsRegisterCounter("hosts.spare", th_v);
 */
     memset(&ts, 0, sizeof(ts));
-    uint32_t hash_passes = 0;
 #ifdef FM_PROFILE
+    uint32_t hash_passes = 0;
     uint32_t hash_row_checks = 0;
     uint32_t hash_passes_chunks = 0;
-#endif
     uint32_t hash_full_passes = 0;
+#endif
 
     const uint32_t min_timeout = FlowTimeoutsMin();
     const uint32_t pass_in_sec = min_timeout ? min_timeout * 8 : 60;
@@ -836,10 +836,9 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
             if (emerg) {
                 /* in emergency mode, do a full pass of the hash table */
                 FlowTimeoutHash(&ftd->timeout, &ts, ftd->min, ftd->max, &counters);
-                hash_passes++;
+#ifdef FM_PROFILE
                 hash_full_passes++;
                 hash_passes++;
-#ifdef FM_PROFILE
                 hash_passes_chunks += 1;
                 hash_row_checks += counters.rows_checked;
 #endif
@@ -853,12 +852,14 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data)
                     hash_pass_iter++;
                     if (hash_pass_iter == pass_in_sec) {
                         hash_pass_iter = 0;
+#ifdef FM_PROFILE
                         hash_full_passes++;
+#endif
                         StatsIncr(th_v, ftd->cnt.flow_mgr_full_pass);
                     }
                 }
-                hash_passes++;
 #ifdef FM_PROFILE
+                hash_passes++;
                 hash_row_checks += counters.rows_checked;
                 hash_passes_chunks += chunks;
 #endif
@@ -1105,9 +1106,9 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
     uint64_t recycled_cnt = 0;
     struct timeval ts;
     memset(&ts, 0, sizeof(ts));
-    uint32_t fr_passes = 0;
 
 #ifdef FM_PROFILE
+    uint32_t fr_passes = 0;
     struct timeval endts;
     struct timeval active;
     struct timeval paused;
@@ -1144,8 +1145,8 @@ static TmEcode FlowRecycler(ThreadVars *th_v, void *thread_data)
 #endif
             TmThreadsUnsetFlag(th_v, THV_PAUSED);
         }
-        fr_passes++;
 #ifdef FM_PROFILE
+        fr_passes++;
         struct timeval run_startts;
         memset(&run_startts, 0, sizeof(run_startts));
         gettimeofday(&run_startts, NULL);
@@ -1286,8 +1287,6 @@ void FlowRecyclerThreadSpawn(void)
  */
 void FlowDisableFlowRecyclerThread(void)
 {
-    int cnt = 0;
-
     /* move all flows still in the hash to the recycler queue */
 #ifndef DEBUG
     (void)FlowCleanupHash();
@@ -1309,7 +1308,6 @@ void FlowDisableFlowRecyclerThread(void)
             strlen(thread_name_flow_rec)) == 0)
         {
             TmThreadsSetFlag(tv, THV_KILL);
-            cnt++;
         }
     }
     SCMutexUnlock(&tv_root_lock);
index 61059a03a28efeb618d3a4cf5096484348af55fd..fc2c0da2e8329104d46e33be5596fe808e77c488 100644 (file)
@@ -87,7 +87,6 @@ static void EveFTPLogCommand(Flow *f, FTPTransaction *tx, JsonBuilder *jb)
     bool reply_truncated = false;
 
     if (!TAILQ_EMPTY(&tx->response_list)) {
-        int resp_code_cnt = 0;
         int resp_cnt = 0;
         FTPString *response;
         bool is_cc_array_open = false;
@@ -115,7 +114,6 @@ static void EveFTPLogCommand(Flow *f, FTPTransaction *tx, JsonBuilder *jb)
                             is_cc_array_open = true;
                         }
                         jb_append_string_from_bytes(jb, (const uint8_t *)where, 3);
-                        resp_code_cnt++;
                         offset = 4;
                     }
                 }
index 6c89ca6363934e4aaa13c40224eaf4bebf564d46..a972e1198849c616bf3352dd4edb46e73df3b9fe 100644 (file)
@@ -277,7 +277,6 @@ static int LiveSafeDeviceName(const char *devname, char *newdevname, size_t dest
  */
 LiveDevice *LiveGetDevice(const char *name)
 {
-    int i = 0;
     LiveDevice *pd;
 
     if (name == NULL) {
@@ -289,8 +288,6 @@ LiveDevice *LiveGetDevice(const char *name)
         if (!strcmp(name, pd->dev)) {
             return pd;
         }
-
-        i++;
     }
 
     return NULL;
index fc0ff0f5df39384bdf9673c3ac47f9343cd4f762..b4cf03c6bdb41bd23b27ddbc499c9514b4539a44 100644 (file)
@@ -325,8 +325,6 @@ static int SCRConfIsLineBlankOrComment(char *line)
 static bool SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
 {
     char line[1024];
-    uint8_t i = 1;
-
     int runmode = RunmodeGetCurrent();
     bool is_conf_test_mode = runmode == RUNMODE_CONF_TEST;
     while (fgets(line, sizeof(line), fd) != NULL) {
@@ -338,7 +336,6 @@ static bool SCRConfParseFile(DetectEngineCtx *de_ctx, FILE *fd)
                 return false;
             }
         }
-        i++;
     }
 
 #ifdef UNITTESTS