From: Anoop Saldanha Date: Thu, 29 Mar 2012 04:39:18 +0000 (+0530) Subject: fix cppcheck analyzer warnings - bug 439 X-Git-Tag: suricata-1.3beta1~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c22755fec5d46831f889cf9bdb291694c32f6a2c;p=thirdparty%2Fsuricata.git fix cppcheck analyzer warnings - bug 439 --- diff --git a/src/detect-fast-pattern.c b/src/detect-fast-pattern.c index 4390e8e37a..da68d33850 100644 --- a/src/detect-fast-pattern.c +++ b/src/detect-fast-pattern.c @@ -11209,8 +11209,8 @@ int DetectFastPatternTest387(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HSMDMATCH]; - DetectContentData *ud = sm->ctx; if (sm != NULL) { + DetectContentData *ud = sm->ctx; if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && @@ -11245,8 +11245,8 @@ int DetectFastPatternTest388(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HSMDMATCH]; - DetectContentData *ud = sm->ctx; if (sm != NULL) { + DetectContentData *ud = sm->ctx; if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && @@ -12392,8 +12392,8 @@ int DetectFastPatternTest428(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HSCDMATCH]; - DetectContentData *ud = sm->ctx; if (sm != NULL) { + DetectContentData *ud = sm->ctx; if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && @@ -12428,8 +12428,8 @@ int DetectFastPatternTest429(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HSCDMATCH]; - DetectContentData *ud = sm->ctx; if (sm != NULL) { + DetectContentData *ud = sm->ctx; if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && @@ -13576,8 +13576,8 @@ int DetectFastPatternTest469(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HSCDMATCH]; - DetectContentData *ud = sm->ctx; if (sm != NULL) { + DetectContentData *ud = sm->ctx; if (ud->flags & DETECT_CONTENT_FAST_PATTERN && ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP) && @@ -13612,8 +13612,8 @@ int DetectFastPatternTest470(void) result = 0; sm = de_ctx->sig_list->sm_lists[DETECT_SM_LIST_HSCDMATCH]; - DetectContentData *ud = sm->ctx; if (sm != NULL) { + DetectContentData *ud = sm->ctx; if (ud->flags & DETECT_CONTENT_FAST_PATTERN && !(ud->flags & DETECT_CONTENT_FAST_PATTERN_ONLY) && ud->flags & DETECT_CONTENT_FAST_PATTERN_CHOP && diff --git a/src/util-debug.h b/src/util-debug.h index 8cf2a4ee9e..0d98d429c2 100644 --- a/src/util-debug.h +++ b/src/util-debug.h @@ -192,7 +192,7 @@ extern int sc_log_module_cleaned; #define SCLog(x, ...) do { \ - char _sc_log_msg[SC_LOG_MAX_LOG_MSG_LEN]; \ + char _sc_log_msg[SC_LOG_MAX_LOG_MSG_LEN] = ""; \ char *_sc_log_temp = _sc_log_msg; \ if ( !( \ (sc_log_global_log_level >= x) && \ @@ -211,7 +211,7 @@ extern int sc_log_module_cleaned; } while(0) #define SCLogErr(x, err, ...) do { \ - char _sc_log_err_msg[SC_LOG_MAX_LOG_MSG_LEN]; \ + char _sc_log_err_msg[SC_LOG_MAX_LOG_MSG_LEN] = ""; \ char *_sc_log_err_temp = _sc_log_err_msg; \ if ( !( \ (sc_log_global_log_level >= x) && \ @@ -360,7 +360,7 @@ extern int sc_log_module_cleaned; __FUNCTION__) == SC_OK) { \ snprintf(_sc_enter_temp, (SC_LOG_MAX_LOG_MSG_LEN - \ (_sc_enter_msg - _sc_enter_temp)), \ - "%s", "Entering ... >>"); \ + "Entering ... >>"); \ SCLogOutputBuffer(SC_LOG_DEBUG, \ _sc_enter_msg); \ } \ @@ -467,9 +467,12 @@ extern int sc_log_module_cleaned; */ #define SCReturnCharPtr(x) do { \ if (sc_log_global_log_level >= SC_LOG_DEBUG) { \ - SCLogDebug("Returning: %s ... <<", x); \ - SCLogCheckFDFilterExit(__FUNCTION__); \ - } \ + if ((x) != NULL) { \ + SCLogDebug("Returning: %s ... <<", x); \ + } else { \ + SCLogDebug("Returning: NULL ... <<"); \ + } SCLogCheckFDFilterExit(__FUNCTION__); \ + } \ return x; \ } while(0) diff --git a/src/util-mem.h b/src/util-mem.h index 6aedaa1fcf..2bcf0ed5d7 100644 --- a/src/util-mem.h +++ b/src/util-mem.h @@ -65,10 +65,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); } \ \ global_mem += (a); \ - if (print_mem_flag == 1) \ + if (print_mem_flag == 1) { \ SCLogInfo("SCMalloc return at %p of size %"PRIuMAX, \ ptrmem, (uintmax_t)(a)); \ - \ + } \ (void*)ptrmem; \ }) @@ -88,10 +88,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); } \ \ global_mem += (a); \ - if (print_mem_flag == 1) \ + if (print_mem_flag == 1) { \ SCLogInfo("SCRealloc return at %p (old:%p) of size %"PRIuMAX, \ ptrmem, (x), (uintmax_t)(a)); \ - \ + } \ (void*)ptrmem; \ }) @@ -111,10 +111,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); } \ \ global_mem += (a)*(nm); \ - if (print_mem_flag == 1) \ + if (print_mem_flag == 1) { \ SCLogInfo("SCCalloc return at %p of size %"PRIuMAX" (nm) %"PRIuMAX, \ ptrmem, (uintmax_t)(a), (uintmax_t)(nm)); \ - \ + } \ (void*)ptrmem; \ }) @@ -135,17 +135,18 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); } \ \ global_mem += len; \ - if (print_mem_flag == 1) \ + if (print_mem_flag == 1) { \ SCLogInfo("SCStrdup return at %p of size %"PRIuMAX, \ ptrmem, (uintmax_t)len); \ - \ + } \ (void*)ptrmem; \ }) #define SCFree(a) ({ \ extern uint8_t print_mem_flag; \ - if (print_mem_flag == 1) \ + if (print_mem_flag == 1) { \ SCLogInfo("SCFree at %p", (a)); \ + } \ free((a)); \ }) diff --git a/src/util-mpm-b2g-cuda.c b/src/util-mpm-b2g-cuda.c index 3ef10d27fc..37756ae3af 100644 --- a/src/util-mpm-b2g-cuda.c +++ b/src/util-mpm-b2g-cuda.c @@ -1689,8 +1689,11 @@ TmEcode B2gCudaMpmDispThreadInit(ThreadVars *tv, void *initdata, void **data) MpmCudaConf *profile = NULL; SCCudaHlModuleData *module_data = (SCCudaHlModuleData *)initdata; - if (PatternMatchDefaultMatcher() != MPM_B2G_CUDA) - return TM_ECODE_OK; + if (PatternMatchDefaultMatcher() != MPM_B2G_CUDA) { + SCLogError(SC_ERR_B2G_CUDA_ERROR, "b2g cuda mpm sees mpm that is " + "not b2g_cuda"); + exit(EXIT_FAILURE); + } if (SCCudaCtxPushCurrent(module_data->cuda_context) == -1) { SCLogError(SC_ERR_B2G_CUDA_ERROR, "Error pushing cuda context");