From deb511f51a58813fc81898a613ef89507447833a Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 2 Nov 2009 12:50:51 +0100 Subject: [PATCH] Fix a compiler warning on Ubuntu 9.10 gcc 4.4.1 in the pattern matchers where the size of the thread ctx can be optimized to 0. --- config.h.in | 3 +++ src/util-mpm-b2g.c | 28 +++++++++++---------- src/util-mpm-b3g.c | 28 +++++++++++---------- src/util-mpm-wumanber.c | 54 +++++++++++++++++++++++------------------ 4 files changed, 63 insertions(+), 50 deletions(-) diff --git a/config.h.in b/config.h.in index 83df21570d..b570a556ff 100644 --- a/config.h.in +++ b/config.h.in @@ -130,6 +130,9 @@ /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME +/* Define to the home page for this package. */ +#undef PACKAGE_URL + /* Define to the version of this package. */ #undef PACKAGE_VERSION diff --git a/src/util-mpm-b2g.c b/src/util-mpm-b2g.c index 7427de851e..3b5408909b 100644 --- a/src/util-mpm-b2g.c +++ b/src/util-mpm-b2g.c @@ -1034,14 +1034,16 @@ void B2gDestroyCtx(MpmCtx *mpm_ctx) { void B2gThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, uint32_t matchsize) { memset(mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); - mpm_thread_ctx->ctx = malloc(sizeof(B2gThreadCtx)); - if (mpm_thread_ctx->ctx == NULL) - return; + if (sizeof(B2gThreadCtx) > 0) { /* size can be null when optimized */ + mpm_thread_ctx->ctx = malloc(sizeof(B2gThreadCtx)); + if (mpm_thread_ctx->ctx == NULL) + return; - memset(mpm_thread_ctx->ctx, 0, sizeof(B2gThreadCtx)); + memset(mpm_thread_ctx->ctx, 0, sizeof(B2gThreadCtx)); - mpm_thread_ctx->memory_cnt++; - mpm_thread_ctx->memory_size += sizeof(B2gThreadCtx); + mpm_thread_ctx->memory_cnt++; + mpm_thread_ctx->memory_size += sizeof(B2gThreadCtx); + } /* alloc an array with the size of _all_ keys in all instances. * this is done so the detect engine won't have to care about @@ -1068,18 +1070,18 @@ void B2gThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { B2gPrintSearchStats(mpm_thread_ctx); - if (ctx) { - if (mpm_thread_ctx->match != NULL) { - mpm_thread_ctx->memory_cnt--; - mpm_thread_ctx->memory_size -= ((mpm_thread_ctx->matchsize + 1) * sizeof(MpmMatchBucket)); - free(mpm_thread_ctx->match); - } - + if (ctx != NULL) { /* can be NULL if B2gThreadCtx is optimized to 0 */ mpm_thread_ctx->memory_cnt--; mpm_thread_ctx->memory_size -= sizeof(B2gThreadCtx); free(mpm_thread_ctx->ctx); } + if (mpm_thread_ctx->match != NULL) { + mpm_thread_ctx->memory_cnt--; + mpm_thread_ctx->memory_size -= ((mpm_thread_ctx->matchsize + 1) * sizeof(MpmMatchBucket)); + free(mpm_thread_ctx->match); + } + MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->sparelist); MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->qlist); } diff --git a/src/util-mpm-b3g.c b/src/util-mpm-b3g.c index 2004228226..6627394a58 100644 --- a/src/util-mpm-b3g.c +++ b/src/util-mpm-b3g.c @@ -1084,14 +1084,16 @@ void B3gDestroyCtx(MpmCtx *mpm_ctx) { void B3gThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, uint32_t matchsize) { memset(mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); - mpm_thread_ctx->ctx = malloc(sizeof(B3gThreadCtx)); - if (mpm_thread_ctx->ctx == NULL) - return; + if (sizeof(B3gThreadCtx) > 0) { /* size can be 0 when optimized */ + mpm_thread_ctx->ctx = malloc(sizeof(B3gThreadCtx)); + if (mpm_thread_ctx->ctx == NULL) + return; - memset(mpm_thread_ctx->ctx, 0, sizeof(B3gThreadCtx)); + memset(mpm_thread_ctx->ctx, 0, sizeof(B3gThreadCtx)); - mpm_thread_ctx->memory_cnt++; - mpm_thread_ctx->memory_size += sizeof(B3gThreadCtx); + mpm_thread_ctx->memory_cnt++; + mpm_thread_ctx->memory_size += sizeof(B3gThreadCtx); + } /* alloc an array with the size of _all_ keys in all instances. * this is done so the detect engine won't have to care about @@ -1118,18 +1120,18 @@ void B3gThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { B3gPrintSearchStats(mpm_thread_ctx); - if (ctx) { - if (mpm_thread_ctx->match != NULL) { - mpm_thread_ctx->memory_cnt--; - mpm_thread_ctx->memory_size -= ((mpm_thread_ctx->matchsize + 1) * sizeof(MpmMatchBucket)); - free(mpm_thread_ctx->match); - } - + if (ctx != NULL) { /* can be NULL when optimized */ mpm_thread_ctx->memory_cnt--; mpm_thread_ctx->memory_size -= sizeof(B3gThreadCtx); free(mpm_thread_ctx->ctx); } + if (mpm_thread_ctx->match != NULL) { + mpm_thread_ctx->memory_cnt--; + mpm_thread_ctx->memory_size -= ((mpm_thread_ctx->matchsize + 1) * sizeof(MpmMatchBucket)); + free(mpm_thread_ctx->match); + } + MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->sparelist); MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->qlist); } diff --git a/src/util-mpm-wumanber.c b/src/util-mpm-wumanber.c index dc08245dbf..f7f7deb2ac 100644 --- a/src/util-mpm-wumanber.c +++ b/src/util-mpm-wumanber.c @@ -2316,14 +2316,16 @@ void WmDestroyCtx(MpmCtx *mpm_ctx) { void WmThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, uint32_t matchsize) { memset(mpm_thread_ctx, 0, sizeof(MpmThreadCtx)); - mpm_thread_ctx->ctx = malloc(sizeof(WmThreadCtx)); - if (mpm_thread_ctx->ctx == NULL) - return; + if (sizeof(WmThreadCtx) > 0) { /* size can be 0 when optimized */ + mpm_thread_ctx->ctx = malloc(sizeof(WmThreadCtx)); + if (mpm_thread_ctx->ctx == NULL) + return; - memset(mpm_thread_ctx->ctx, 0, sizeof(WmThreadCtx)); + memset(mpm_thread_ctx->ctx, 0, sizeof(WmThreadCtx)); - mpm_thread_ctx->memory_cnt++; - mpm_thread_ctx->memory_size += sizeof(WmThreadCtx); + mpm_thread_ctx->memory_cnt++; + mpm_thread_ctx->memory_size += sizeof(WmThreadCtx); + } /* alloc an array with the size of _all_ keys in all instances. * this is done so the detect engine won't have to care about @@ -2347,18 +2349,18 @@ void WmThreadInitCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx, uint32_t mat void WmThreadDestroyCtx(MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx) { WmThreadCtx *ctx = (WmThreadCtx *)mpm_thread_ctx->ctx; - if (ctx) { - if (mpm_thread_ctx->match != NULL) { - mpm_thread_ctx->memory_cnt--; - mpm_thread_ctx->memory_size -= ((mpm_thread_ctx->matchsize + 1) * sizeof(MpmMatchBucket)); - free(mpm_thread_ctx->match); - } - + if (ctx != NULL) { /* size can be 0 when optimized */ mpm_thread_ctx->memory_cnt--; mpm_thread_ctx->memory_size -= sizeof(WmThreadCtx); free(mpm_thread_ctx->ctx); } + if (mpm_thread_ctx->match != NULL) { + mpm_thread_ctx->memory_cnt--; + mpm_thread_ctx->memory_size -= ((mpm_thread_ctx->matchsize + 1) * sizeof(MpmMatchBucket)); + free(mpm_thread_ctx->match); + } + MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->sparelist); MpmMatchFreeSpares(mpm_thread_ctx, mpm_thread_ctx->qlist); } @@ -2410,20 +2412,24 @@ int WmTestInitCtx03 (void) { } int WmTestThreadInitCtx01 (void) { - int result = 0; - MpmCtx mpm_ctx; - memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); - MpmThreadCtx mpm_thread_ctx; + if (sizeof(WmThreadCtx) > 0) { + int result = 0; + MpmCtx mpm_ctx; + memset(&mpm_ctx, 0x00, sizeof(MpmCtx)); + MpmThreadCtx mpm_thread_ctx; - MpmInitCtx(&mpm_ctx, MPM_WUMANBER); - WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); + MpmInitCtx(&mpm_ctx, MPM_WUMANBER); + WmThreadInitCtx(&mpm_ctx, &mpm_thread_ctx, 1); - if (mpm_thread_ctx.memory_cnt == 2) - result = 1; + if (mpm_thread_ctx.memory_cnt == 2) + result = 1; - WmThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); - WmDestroyCtx(&mpm_ctx); - return result; + WmThreadDestroyCtx(&mpm_ctx, &mpm_thread_ctx); + WmDestroyCtx(&mpm_ctx); + return result; + } else { + return 1; + } } int WmTestThreadInitCtx02 (void) {