From 0a17103ab85bab1da380a9fd8057429fa408eab0 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 16 Jan 2023 22:09:02 +0100 Subject: [PATCH] src: fix unused-but-set-variable compile warnings 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 | 12 ++++-------- src/detect-engine-build.c | 4 ---- src/detect-engine-enip.c | 4 ++++ src/detect-engine-iponly.c | 5 ++++- src/detect-engine-port.c | 5 ++++- src/detect-engine-sigorder.c | 9 ++++++++- src/flow-manager.c | 18 ++++++++---------- src/output-json-ftp.c | 2 -- src/util-device.c | 3 --- src/util-reference-config.c | 3 --- 10 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/datasets.c b/src/datasets.c index 1ca7ca1b0b..b0dea2f304 100644 --- a/src/datasets.c +++ b/src/datasets.c @@ -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++; diff --git a/src/detect-engine-build.c b/src/detect-engine-build.c index 5901f9283d..3c1d9acde3 100644 --- a/src/detect-engine-build.c +++ b/src/detect-engine-build.c @@ -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); diff --git a/src/detect-engine-enip.c b/src/detect-engine-enip.c index 3dcb681a82..adc41557d5 100644 --- a/src/detect-engine-enip.c +++ b/src/detect-engine-enip.c @@ -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; } diff --git a/src/detect-engine-iponly.c b/src/detect-engine-iponly.c index e9604384a3..d06d28e06f 100644 --- a/src/detect-engine-iponly.c +++ b/src/detect-engine-iponly.c @@ -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; diff --git a/src/detect-engine-port.c b/src/detect-engine-port.c index 43a68f3256..c5286886ac 100644 --- a/src/detect-engine-port.c +++ b/src/detect-engine-port.c @@ -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(" "); } diff --git a/src/detect-engine-sigorder.c b/src/detect-engine-sigorder.c index 3c0c1e9697..8859ab16d0 100644 --- a/src/detect-engine-sigorder.c +++ b/src/detect-engine-sigorder.c @@ -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 */ diff --git a/src/flow-manager.c b/src/flow-manager.c index cdb611c07e..bb1e720fcb 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -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); diff --git a/src/output-json-ftp.c b/src/output-json-ftp.c index 61059a03a2..fc2c0da2e8 100644 --- a/src/output-json-ftp.c +++ b/src/output-json-ftp.c @@ -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; } } diff --git a/src/util-device.c b/src/util-device.c index 6c89ca6363..a972e11988 100644 --- a/src/util-device.c +++ b/src/util-device.c @@ -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; diff --git a/src/util-reference-config.c b/src/util-reference-config.c index fc0ff0f5df..b4cf03c6bd 100644 --- a/src/util-reference-config.c +++ b/src/util-reference-config.c @@ -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