From ec1482cf4811b74715c3ce4bd35dc1c70680f01d Mon Sep 17 00:00:00 2001 From: Jeff Lucovsky Date: Tue, 21 Nov 2023 08:55:28 -0500 Subject: [PATCH] calloc: Use nmemb with SCCalloc This commit modifies calls to SCCalloc that had a member count of 1 and a size count calculated as: element_count * sizeof(element). --- src/app-layer-detect-proto.c | 2 +- src/detect-engine-build.c | 2 +- src/detect-engine-siggroup.c | 6 +++--- src/detect-engine.c | 4 ++-- src/util-bloomfilter-counting.c | 2 +- src/util-hash.c | 2 +- src/util-hashlist.c | 2 +- src/util-mpm-ac-bs.c | 12 ++++++------ src/util-mpm-ac-ks.c | 6 +++--- src/util-mpm-ac.c | 8 ++++---- src/util-mpm-hs.c | 14 +++++++------- src/util-profiling-keywords.c | 8 ++++---- src/util-profiling-rules.c | 4 ++-- src/util-storage.c | 6 +++--- 14 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/app-layer-detect-proto.c b/src/app-layer-detect-proto.c index cb31b4d6b9..690950d34e 100644 --- a/src/app-layer-detect-proto.c +++ b/src/app-layer-detect-proto.c @@ -1268,7 +1268,7 @@ static int AppLayerProtoDetectPMMapSignatures(AppLayerProtoDetectPMCtx *ctx) int mpm_ret; SigIntId id = 0; - ctx->map = SCCalloc(1, ctx->max_sig_id * sizeof(AppLayerProtoDetectPMSignature *)); + ctx->map = SCCalloc(ctx->max_sig_id, sizeof(AppLayerProtoDetectPMSignature *)); if (ctx->map == NULL) goto error; diff --git a/src/detect-engine-build.c b/src/detect-engine-build.c index f632bd8e5b..8c01104c48 100644 --- a/src/detect-engine-build.c +++ b/src/detect-engine-build.c @@ -1383,7 +1383,7 @@ int SigAddressPrepareStage1(DetectEngineCtx *de_ctx) de_ctx->sig_array_len = DetectEngineGetMaxSigId(de_ctx); de_ctx->sig_array_size = (de_ctx->sig_array_len * sizeof(Signature *)); - de_ctx->sig_array = (Signature **)SCCalloc(1, de_ctx->sig_array_size); + de_ctx->sig_array = (Signature **)SCCalloc(de_ctx->sig_array_len, sizeof(Signature *)); if (de_ctx->sig_array == NULL) goto error; diff --git a/src/detect-engine-siggroup.c b/src/detect-engine-siggroup.c index 36e3872c04..36df347a50 100644 --- a/src/detect-engine-siggroup.c +++ b/src/detect-engine-siggroup.c @@ -493,7 +493,7 @@ int SigGroupHeadBuildMatchArray(DetectEngineCtx *de_ctx, SigGroupHead *sgh, BUG_ON(sgh->init->match_array != NULL); - sgh->init->match_array = SCCalloc(1, sgh->init->sig_cnt * sizeof(Signature *)); + sgh->init->match_array = SCCalloc(sgh->init->sig_cnt, sizeof(Signature *)); if (sgh->init->match_array == NULL) return -1; @@ -672,12 +672,12 @@ int SigGroupHeadBuildNonPrefilterArray(DetectEngineCtx *de_ctx, SigGroupHead *sg } if (non_pf > 0) { - sgh->non_pf_other_store_array = SCCalloc(1, non_pf * sizeof(SignatureNonPrefilterStore)); + sgh->non_pf_other_store_array = SCCalloc(non_pf, sizeof(SignatureNonPrefilterStore)); BUG_ON(sgh->non_pf_other_store_array == NULL); } if (non_pf_syn > 0) { - sgh->non_pf_syn_store_array = SCCalloc(1, non_pf_syn * sizeof(SignatureNonPrefilterStore)); + sgh->non_pf_syn_store_array = SCCalloc(non_pf_syn, sizeof(SignatureNonPrefilterStore)); BUG_ON(sgh->non_pf_syn_store_array == NULL); } diff --git a/src/detect-engine.c b/src/detect-engine.c index 678031fa44..4cf145df6e 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -3046,7 +3046,7 @@ static int DetectEngineThreadCtxInitKeywords(DetectEngineCtx *de_ctx, DetectEngi { if (de_ctx->keyword_id > 0) { // coverity[suspicious_sizeof : FALSE] - det_ctx->keyword_ctxs_array = SCCalloc(1, de_ctx->keyword_id * sizeof(void *)); + det_ctx->keyword_ctxs_array = SCCalloc(de_ctx->keyword_id, sizeof(void *)); if (det_ctx->keyword_ctxs_array == NULL) { SCLogError("setting up thread local detect ctx"); return TM_ECODE_FAILED; @@ -3226,7 +3226,7 @@ static TmEcode ThreadCtxDoInit (DetectEngineCtx *de_ctx, DetectEngineThreadCtx * /* DeState */ if (de_ctx->sig_array_len > 0) { det_ctx->match_array_len = de_ctx->sig_array_len; - det_ctx->match_array = SCCalloc(1, det_ctx->match_array_len * sizeof(Signature *)); + det_ctx->match_array = SCCalloc(det_ctx->match_array_len, sizeof(Signature *)); if (det_ctx->match_array == NULL) { return TM_ECODE_FAILED; } diff --git a/src/util-bloomfilter-counting.c b/src/util-bloomfilter-counting.c index 6fc9cadc7d..620b507dfa 100644 --- a/src/util-bloomfilter-counting.c +++ b/src/util-bloomfilter-counting.c @@ -57,7 +57,7 @@ BloomFilterCounting *BloomFilterCountingInit(uint32_t size, uint8_t type, uint8_ bf->Hash = Hash; /* setup the bitarray */ - bf->array = SCCalloc(1, bf->array_size * bf->type); + bf->array = SCCalloc(bf->array_size, bf->type); if (bf->array == NULL) goto error; diff --git a/src/util-hash.c b/src/util-hash.c index a81882d52a..412a46fa7e 100644 --- a/src/util-hash.c +++ b/src/util-hash.c @@ -59,7 +59,7 @@ HashTable* HashTableInit(uint32_t size, uint32_t (*Hash)(struct HashTable_ *, vo ht->Compare = HashTableDefaultCompare; /* setup the bitarray */ - ht->array = SCCalloc(1, ht->array_size * sizeof(HashTableBucket *)); + ht->array = SCCalloc(ht->array_size, sizeof(HashTableBucket *)); if (ht->array == NULL) goto error; diff --git a/src/util-hashlist.c b/src/util-hashlist.c index 88f8144b3c..e4b62a613d 100644 --- a/src/util-hashlist.c +++ b/src/util-hashlist.c @@ -65,7 +65,7 @@ HashListTable *HashListTableInit(uint32_t size, ht->Compare = HashListTableDefaultCompare; /* setup the bitarray */ - ht->array = SCCalloc(1, ht->array_size * sizeof(HashListTableBucket *)); + ht->array = SCCalloc(ht->array_size, sizeof(HashListTableBucket *)); if (ht->array == NULL) { sc_errno = SC_ENOMEM; goto error; diff --git a/src/util-mpm-ac-bs.c b/src/util-mpm-ac-bs.c index aebcd778a6..72d2065ca7 100644 --- a/src/util-mpm-ac-bs.c +++ b/src/util-mpm-ac-bs.c @@ -420,7 +420,7 @@ static inline void SCACBSCreateFailureTable(MpmCtx *mpm_ctx) /* allot space for the failure table. A failure entry in the table for * every state(SCACBSCtx->state_count) */ - ctx->failure_table = SCCalloc(1, ctx->state_count * sizeof(int32_t)); + ctx->failure_table = SCCalloc(ctx->state_count, sizeof(int32_t)); if (ctx->failure_table == NULL) { FatalError("Error allocating memory"); } @@ -681,7 +681,7 @@ static inline void SCACBSCreateModDeltaTable(MpmCtx *mpm_ctx) /* buffer to hold pointers in the buffer, so that a state can use it * directly to access its state data */ - ctx->state_table_mod_pointers = SCCalloc(1, ctx->state_count * sizeof(uint8_t *)); + ctx->state_table_mod_pointers = SCCalloc(ctx->state_count, sizeof(uint8_t *)); if (ctx->state_table_mod_pointers == NULL) { FatalError("Error allocating memory"); } @@ -750,7 +750,7 @@ static inline void SCACBSCreateModDeltaTable(MpmCtx *mpm_ctx) /* buffer to hold pointers in the buffer, so that a state can use it * directly to access its state data */ - ctx->state_table_mod_pointers = SCCalloc(1, ctx->state_count * sizeof(uint8_t *)); + ctx->state_table_mod_pointers = SCCalloc(ctx->state_count, sizeof(uint8_t *)); if (ctx->state_table_mod_pointers == NULL) { FatalError("Error allocating memory"); } @@ -861,7 +861,7 @@ int SCACBSPreparePatterns(MpmCtx *mpm_ctx) } /* alloc the pattern array */ - ctx->parray = (MpmPattern **)SCCalloc(1, mpm_ctx->pattern_cnt * sizeof(MpmPattern *)); + ctx->parray = (MpmPattern **)SCCalloc(mpm_ctx->pattern_cnt, sizeof(MpmPattern *)); if (ctx->parray == NULL) goto error; mpm_ctx->memory_cnt++; @@ -887,7 +887,7 @@ int SCACBSPreparePatterns(MpmCtx *mpm_ctx) ctx->single_state_size = sizeof(int32_t) * 256; /* handle no case patterns */ - ctx->pid_pat_list = SCCalloc(1, (mpm_ctx->max_pat_id + 1) * sizeof(SCACBSPatternList)); + ctx->pid_pat_list = SCCalloc((mpm_ctx->max_pat_id + 1), sizeof(SCACBSPatternList)); if (ctx->pid_pat_list == NULL) { FatalError("Error allocating memory"); } @@ -949,7 +949,7 @@ void SCACBSInitCtx(MpmCtx *mpm_ctx) mpm_ctx->memory_size += sizeof(SCACBSCtx); /* initialize the hash we use to speed up pattern insertions */ - mpm_ctx->init_hash = SCCalloc(1, sizeof(MpmPattern *) * MPM_INIT_HASH_SIZE); + mpm_ctx->init_hash = SCCalloc(MPM_INIT_HASH_SIZE, sizeof(MpmPattern *)); if (mpm_ctx->init_hash == NULL) { exit(EXIT_FAILURE); } diff --git a/src/util-mpm-ac-ks.c b/src/util-mpm-ac-ks.c index 9b2c799eef..b2f3ebc1af 100644 --- a/src/util-mpm-ac-ks.c +++ b/src/util-mpm-ac-ks.c @@ -508,7 +508,7 @@ static void SCACTileCreateFailureTable(MpmCtx *mpm_ctx) /* Allocate space for the failure table. A failure entry in the table for * every state(SCACTileCtx->state_count) */ - ctx->failure_table = SCCalloc(1, ctx->state_count * sizeof(int32_t)); + ctx->failure_table = SCCalloc(ctx->state_count, sizeof(int32_t)); if (ctx->failure_table == NULL) { FatalError("Error allocating memory"); } @@ -874,7 +874,7 @@ int SCACTilePreparePatterns(MpmCtx *mpm_ctx) } /* alloc the pattern array */ - ctx->parray = (MpmPattern **)SCCalloc(1, mpm_ctx->pattern_cnt * sizeof(MpmPattern *)); + ctx->parray = (MpmPattern **)SCCalloc(mpm_ctx->pattern_cnt, sizeof(MpmPattern *)); if (ctx->parray == NULL) goto error; @@ -985,7 +985,7 @@ void SCACTileInitCtx(MpmCtx *mpm_ctx) mpm_ctx->memory_size += sizeof(SCACTileCtx); /* initialize the hash we use to speed up pattern insertions */ - mpm_ctx->init_hash = SCCalloc(1, sizeof(MpmPattern *) * MPM_INIT_HASH_SIZE); + mpm_ctx->init_hash = SCCalloc(MPM_INIT_HASH_SIZE, sizeof(MpmPattern *)); if (mpm_ctx->init_hash == NULL) { exit(EXIT_FAILURE); } diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index cb663b8aba..22347d6fef 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -476,7 +476,7 @@ static inline void SCACCreateFailureTable(MpmCtx *mpm_ctx) /* allot space for the failure table. A failure entry in the table for * every state(SCACCtx->state_count) */ - ctx->failure_table = SCCalloc(1, ctx->state_count * sizeof(int32_t)); + ctx->failure_table = SCCalloc(ctx->state_count, sizeof(int32_t)); if (ctx->failure_table == NULL) { FatalError("Error allocating memory"); } @@ -736,7 +736,7 @@ int SCACPreparePatterns(MpmCtx *mpm_ctx) } /* alloc the pattern array */ - ctx->parray = (MpmPattern **)SCCalloc(1, mpm_ctx->pattern_cnt * sizeof(MpmPattern *)); + ctx->parray = (MpmPattern **)SCCalloc(mpm_ctx->pattern_cnt, sizeof(MpmPattern *)); if (ctx->parray == NULL) goto error; mpm_ctx->memory_cnt++; @@ -762,7 +762,7 @@ int SCACPreparePatterns(MpmCtx *mpm_ctx) ctx->single_state_size = sizeof(int32_t) * 256; /* handle no case patterns */ - ctx->pid_pat_list = SCCalloc(1, (mpm_ctx->max_pat_id + 1) * sizeof(SCACPatternList)); + ctx->pid_pat_list = SCCalloc((mpm_ctx->max_pat_id + 1), sizeof(SCACPatternList)); if (ctx->pid_pat_list == NULL) { FatalError("Error allocating memory"); } @@ -831,7 +831,7 @@ void SCACInitCtx(MpmCtx *mpm_ctx) mpm_ctx->memory_size += sizeof(SCACCtx); /* initialize the hash we use to speed up pattern insertions */ - mpm_ctx->init_hash = SCCalloc(1, sizeof(MpmPattern *) * MPM_INIT_HASH_SIZE); + mpm_ctx->init_hash = SCCalloc(MPM_INIT_HASH_SIZE, sizeof(MpmPattern *)); if (mpm_ctx->init_hash == NULL) { exit(EXIT_FAILURE); } diff --git a/src/util-mpm-hs.c b/src/util-mpm-hs.c index 7f26570981..a3b896abde 100644 --- a/src/util-mpm-hs.c +++ b/src/util-mpm-hs.c @@ -379,29 +379,29 @@ typedef struct SCHSCompileData_ { static SCHSCompileData *SCHSAllocCompileData(unsigned int pattern_cnt) { - SCHSCompileData *cd = SCCalloc(1, pattern_cnt * sizeof(SCHSCompileData)); + SCHSCompileData *cd = SCCalloc(pattern_cnt, sizeof(SCHSCompileData)); if (cd == NULL) { goto error; } cd->pattern_cnt = pattern_cnt; - cd->ids = SCCalloc(1, pattern_cnt * sizeof(unsigned int)); + cd->ids = SCCalloc(pattern_cnt, sizeof(unsigned int)); if (cd->ids == NULL) { goto error; } - cd->flags = SCCalloc(1, pattern_cnt * sizeof(unsigned int)); + cd->flags = SCCalloc(pattern_cnt, sizeof(unsigned int)); if (cd->flags == NULL) { goto error; } - cd->expressions = SCCalloc(1, pattern_cnt * sizeof(char *)); + cd->expressions = SCCalloc(pattern_cnt, sizeof(char *)); if (cd->expressions == NULL) { goto error; } - cd->ext = SCCalloc(1, pattern_cnt * sizeof(hs_expr_ext_t *)); + cd->ext = SCCalloc(pattern_cnt, sizeof(hs_expr_ext_t *)); if (cd->ext == NULL) { goto error; } @@ -559,7 +559,7 @@ static PatternDatabase *PatternDatabaseAlloc(uint32_t pattern_cnt) pd->hs_db = NULL; /* alloc the pattern array */ - pd->parray = (SCHSPattern **)SCCalloc(1, pd->pattern_cnt * sizeof(SCHSPattern *)); + pd->parray = (SCHSPattern **)SCCalloc(pd->pattern_cnt, sizeof(SCHSPattern *)); if (pd->parray == NULL) { SCFree(pd); return NULL; @@ -806,7 +806,7 @@ void SCHSInitCtx(MpmCtx *mpm_ctx) /* initialize the hash we use to speed up pattern insertions */ SCHSCtx *ctx = (SCHSCtx *)mpm_ctx->ctx; - ctx->init_hash = SCCalloc(1, sizeof(SCHSPattern *) * INIT_HASH_SIZE); + ctx->init_hash = SCCalloc(INIT_HASH_SIZE, sizeof(SCHSPattern *)); if (ctx->init_hash == NULL) { exit(EXIT_FAILURE); } diff --git a/src/util-profiling-keywords.c b/src/util-profiling-keywords.c index bd7cda526b..c0620a751b 100644 --- a/src/util-profiling-keywords.c +++ b/src/util-profiling-keywords.c @@ -283,7 +283,7 @@ void SCProfilingKeywordThreadSetup(SCProfileKeywordDetectCtx *ctx, DetectEngineT if (ctx == NULL) return; - SCProfileKeywordData *a = SCCalloc(1, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); + SCProfileKeywordData *a = SCCalloc(DETECT_TBLSIZE, sizeof(SCProfileKeywordData)); if (a != NULL) { det_ctx->keyword_perf_data = a; } @@ -294,7 +294,7 @@ void SCProfilingKeywordThreadSetup(SCProfileKeywordDetectCtx *ctx, DetectEngineT int i; for (i = 0; i < nlists; i++) { - SCProfileKeywordData *b = SCCalloc(1, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); + SCProfileKeywordData *b = SCCalloc(DETECT_TBLSIZE, sizeof(SCProfileKeywordData)); if (b != NULL) { det_ctx->keyword_perf_data_per_list[i] = b; } @@ -369,7 +369,7 @@ SCProfilingKeywordInitCounters(DetectEngineCtx *de_ctx) de_ctx->profile_keyword_ctx = SCProfilingKeywordInitCtx(); BUG_ON(de_ctx->profile_keyword_ctx == NULL); - de_ctx->profile_keyword_ctx->data = SCCalloc(1, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); + de_ctx->profile_keyword_ctx->data = SCCalloc(DETECT_TBLSIZE, sizeof(SCProfileKeywordData)); BUG_ON(de_ctx->profile_keyword_ctx->data == NULL); de_ctx->profile_keyword_ctx_per_list = SCCalloc(nlists, sizeof(SCProfileKeywordDetectCtx *)); @@ -380,7 +380,7 @@ SCProfilingKeywordInitCounters(DetectEngineCtx *de_ctx) de_ctx->profile_keyword_ctx_per_list[i] = SCProfilingKeywordInitCtx(); BUG_ON(de_ctx->profile_keyword_ctx_per_list[i] == NULL); de_ctx->profile_keyword_ctx_per_list[i]->data = - SCCalloc(1, sizeof(SCProfileKeywordData) * DETECT_TBLSIZE); + SCCalloc(DETECT_TBLSIZE, sizeof(SCProfileKeywordData)); BUG_ON(de_ctx->profile_keyword_ctx_per_list[i]->data == NULL); } diff --git a/src/util-profiling-rules.c b/src/util-profiling-rules.c index 0397b8a0c0..8262f71f4c 100644 --- a/src/util-profiling-rules.c +++ b/src/util-profiling-rules.c @@ -588,7 +588,7 @@ void SCProfilingRuleThreadSetup(SCProfileDetectCtx *ctx, DetectEngineThreadCtx * if (ctx == NULL|| ctx->size == 0) return; - SCProfileData *a = SCCalloc(1, sizeof(SCProfileData) * ctx->size); + SCProfileData *a = SCCalloc(ctx->size, sizeof(SCProfileData)); if (a != NULL) { det_ctx->rule_perf_data = a; det_ctx->rule_perf_data_size = ctx->size; @@ -665,7 +665,7 @@ SCProfilingRuleInitCounters(DetectEngineCtx *de_ctx) } if (count > 0) { - de_ctx->profile_ctx->data = SCCalloc(1, sizeof(SCProfileData) * de_ctx->profile_ctx->size); + de_ctx->profile_ctx->data = SCCalloc(de_ctx->profile_ctx->size, sizeof(SCProfileData)); BUG_ON(de_ctx->profile_ctx->data == NULL); sig = de_ctx->sig_list; diff --git a/src/util-storage.c b/src/util-storage.c index 1394f20523..52b819d0e6 100644 --- a/src/util-storage.c +++ b/src/util-storage.c @@ -149,14 +149,14 @@ int StorageFinalize(void) if (count == 0) return 0; - storage_map = SCCalloc(1, sizeof(StorageMapping *) * STORAGE_MAX); + storage_map = SCCalloc(STORAGE_MAX, sizeof(StorageMapping *)); if (unlikely(storage_map == NULL)) { return -1; } for (i = 0; i < STORAGE_MAX; i++) { if (storage_max_id[i] > 0) { - storage_map[i] = SCCalloc(1, sizeof(StorageMapping) * storage_max_id[i]); + storage_map[i] = SCCalloc(storage_max_id[i], sizeof(StorageMapping)); if (storage_map[i] == NULL) return -1; } @@ -262,7 +262,7 @@ void *StorageAllocById(Storage **storage, StorageEnum type, int id) Storage *store = *storage; if (store == NULL) { // coverity[suspicious_sizeof : FALSE] - store = SCCalloc(1, sizeof(void *) * storage_max_id[type]); + store = SCCalloc(storage_max_id[type], sizeof(void *)); if (unlikely(store == NULL)) return NULL; } -- 2.47.2