From: Victor Julien Date: Fri, 21 Apr 2023 09:13:19 +0000 (+0200) Subject: mpm/ac: work around scan-build warnings X-Git-Tag: suricata-7.0.0-rc2~367 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee683a7074d449b5b2b272e70f86caa20b230662;p=thirdparty%2Fsuricata.git mpm/ac: work around scan-build warnings util-mpm-ac.c:531:32: warning: Result of 'malloc' is converted to a pointer of type 'uint16_t[256]', which is incompatible with sizeof operand type 'uint16_t' [unix.MallocSizeof] ctx->state_table_u16 = SCMalloc(ctx->state_count * ^~~~~~~~ ./util-mem.h:35:18: note: expanded from macro 'SCMalloc' #define SCMalloc malloc ^~~~~~ util-mpm-ac.c:575:32: warning: Result of 'malloc' is converted to a pointer of type 'uint32_t[256]', which is incompatible with sizeof operand type 'uint32_t' [unix.MallocSizeof] ctx->state_table_u32 = SCMalloc(ctx->state_count * ^~~~~~~~ ./util-mem.h:35:18: note: expanded from macro 'SCMalloc' #define SCMalloc malloc ^~~~~~ 2 warnings generated. Bug: #3148. --- diff --git a/src/util-mpm-ac.c b/src/util-mpm-ac.c index 65a6e43184..c709207464 100644 --- a/src/util-mpm-ac.c +++ b/src/util-mpm-ac.c @@ -528,17 +528,12 @@ static inline void SCACCreateDeltaTable(MpmCtx *mpm_ctx) int32_t r_state = 0; if ((ctx->state_count < 32767) || construct_both_16_and_32_state_tables) { - ctx->state_table_u16 = SCMalloc(ctx->state_count * - sizeof(SC_AC_STATE_TYPE_U16) * 256); + ctx->state_table_u16 = SCCalloc(ctx->state_count, sizeof(*ctx->state_table_u16)); if (ctx->state_table_u16 == NULL) { FatalError("Error allocating memory"); } - memset(ctx->state_table_u16, 0, - ctx->state_count * sizeof(SC_AC_STATE_TYPE_U16) * 256); - mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (ctx->state_count * - sizeof(SC_AC_STATE_TYPE_U16) * 256); + mpm_ctx->memory_size += (ctx->state_count * sizeof(*ctx->state_table_u16)); StateQueue q; memset(&q, 0, sizeof(StateQueue)); @@ -572,17 +567,12 @@ static inline void SCACCreateDeltaTable(MpmCtx *mpm_ctx) /* create space for the state table. We could have used the existing goto * table, but since we have it set to hold 32 bit state values, we will create * a new state table here of type SC_AC_STATE_TYPE(current set to uint16_t) */ - ctx->state_table_u32 = SCMalloc(ctx->state_count * - sizeof(SC_AC_STATE_TYPE_U32) * 256); + ctx->state_table_u32 = SCCalloc(ctx->state_count, sizeof(*ctx->state_table_u32)); if (ctx->state_table_u32 == NULL) { FatalError("Error allocating memory"); } - memset(ctx->state_table_u32, 0, - ctx->state_count * sizeof(SC_AC_STATE_TYPE_U32) * 256); - mpm_ctx->memory_cnt++; - mpm_ctx->memory_size += (ctx->state_count * - sizeof(SC_AC_STATE_TYPE_U32) * 256); + mpm_ctx->memory_size += (ctx->state_count * sizeof(*ctx->state_table_u32)); StateQueue q; memset(&q, 0, sizeof(StateQueue));