]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
mpm/ac-bs: work around scan-build warnings
authorVictor Julien <vjulien@oisf.net>
Fri, 21 Apr 2023 09:16:13 +0000 (11:16 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 25 Apr 2023 09:36:37 +0000 (11:36 +0200)
util-mpm-ac-bs.c:482: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-bs.c:524: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.
(cherry picked from commit c8694634af14177ffaaaa50875fcf4cccfaa932a)

src/util-mpm-ac-bs.c

index 2a56aa104669db4168d160c959a85c9be21f1455..3a9eeabb91b112d2fa34b16b3e55c2846573bb14 100644 (file)
@@ -479,17 +479,12 @@ static inline void SCACBSCreateDeltaTable(MpmCtx *mpm_ctx)
     int32_t r_state = 0;
 
     if (ctx->state_count < 32767) {
-        ctx->state_table_u16 = SCMalloc(ctx->state_count *
-                                        sizeof(SC_AC_BS_STATE_TYPE_U16) * 256);
+        ctx->state_table_u16 = SCCalloc(ctx->state_count, sizeof(*ctx->state_table_u16));
         if (ctx->state_table_u16 == NULL) {
             FatalError(SC_ERR_FATAL, "Error allocating memory");
         }
-        memset(ctx->state_table_u16, 0,
-               ctx->state_count * sizeof(SC_AC_BS_STATE_TYPE_U16) * 256);
-
         mpm_ctx->memory_cnt++;
-        mpm_ctx->memory_size += (ctx->state_count *
-                                 sizeof(SC_AC_BS_STATE_TYPE_U16) * 256);
+        mpm_ctx->memory_size += (ctx->state_count * sizeof(*ctx->state_table_u16));
 
         StateQueue q;
         memset(&q, 0, sizeof(StateQueue));
@@ -519,17 +514,12 @@ static inline void SCACBSCreateDeltaTable(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_BS_STATE_TYPE(current set to uint16_t) */
-        ctx->state_table_u32 = SCMalloc(ctx->state_count *
-                                        sizeof(SC_AC_BS_STATE_TYPE_U32) * 256);
+        ctx->state_table_u32 = SCCalloc(ctx->state_count, sizeof(*ctx->state_table_u32));
         if (ctx->state_table_u32 == NULL) {
             FatalError(SC_ERR_FATAL, "Error allocating memory");
         }
-        memset(ctx->state_table_u32, 0,
-               ctx->state_count * sizeof(SC_AC_BS_STATE_TYPE_U32) * 256);
-
         mpm_ctx->memory_cnt++;
-        mpm_ctx->memory_size += (ctx->state_count *
-                                 sizeof(SC_AC_BS_STATE_TYPE_U32) * 256);
+        mpm_ctx->memory_size += (ctx->state_count * sizeof(*ctx->state_table_u32));
 
         StateQueue q;
         memset(&q, 0, sizeof(StateQueue));