From 4b425850cf4753942f1c56d2d127342950524131 Mon Sep 17 00:00:00 2001 From: Felipe Zimmerle Date: Thu, 22 Oct 2020 10:08:35 -0300 Subject: [PATCH] Cosmetics: fix cppcheck warnings --- Makefile.am | 2 +- src/modsecurity.cc | 6 +++--- src/request_body_processor/json.cc | 4 ++-- src/utils/geo_lookup.cc | 4 ++-- src/variables/web_app_id.h | 1 - test/cppcheck_suppressions.txt | 4 ++++ 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 734b6f35..ca2cfdf8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -59,7 +59,7 @@ cppcheck: @cppcheck -U YYSTYPE -U MBEDTLS_MD5_ALT -U MBEDTLS_SHA1_ALT \ -D MS_CPPCHECK_DISABLED_FOR_PARSER \ --suppressions-list=./test/cppcheck_suppressions.txt \ - --enable=all \ + --enable=warning,style,performance,portability,unusedFunction,missingInclude \ --inconclusive \ --template="warning: {file},{line},{severity},{id},{message}" \ -I headers -I . -I others -I src -I others/mbedtls -I src/parser \ diff --git a/src/modsecurity.cc b/src/modsecurity.cc index ac8e5256..2dbf4513 100644 --- a/src/modsecurity.cc +++ b/src/modsecurity.cc @@ -256,7 +256,7 @@ int ModSecurity::processContentOffset(const char *content, size_t len, strlen("highlight")); yajl_gen_array_open(g); - while (vars.size() > 0) { + while (vars.size() > 3) { std::string value; yajl_gen_map_open(g); vars.pop_back(); @@ -303,7 +303,7 @@ int ModSecurity::processContentOffset(const char *content, size_t len, varValue.size()); yajl_gen_map_close(g); - while (trans.size() > 0) { + while (!trans.empty()) { modsecurity::actions::transformations::Transformation *t; std::string varValueRes; yajl_gen_map_open(g); @@ -338,7 +338,7 @@ int ModSecurity::processContentOffset(const char *content, size_t len, yajl_gen_map_open(g); - while (ops.size() > 0) { + while (ops.size() > 3) { std::string value; yajl_gen_string(g, reinterpret_cast("highlight"), strlen("highlight")); diff --git a/src/request_body_processor/json.cc b/src/request_body_processor/json.cc index a371623f..219f7385 100644 --- a/src/request_body_processor/json.cc +++ b/src/request_body_processor/json.cc @@ -232,7 +232,7 @@ int JSON::yajl_start_array(void *ctx) { int JSON::yajl_end_array(void *ctx) { JSON *tthis = reinterpret_cast(ctx); - if (tthis->m_containers.size() <= 0) { + if (tthis->m_containers.empty()) { return 1; } @@ -266,7 +266,7 @@ int JSON::yajl_start_map(void *ctx) { */ int JSON::yajl_end_map(void *ctx) { JSON *tthis = reinterpret_cast(ctx); - if (tthis->m_containers.size() <= 0) { + if (tthis->m_containers.empty()) { return 1; } diff --git a/src/utils/geo_lookup.cc b/src/utils/geo_lookup.cc index 00c4592a..ede8730b 100644 --- a/src/utils/geo_lookup.cc +++ b/src/utils/geo_lookup.cc @@ -91,11 +91,11 @@ bool GeoLookup::setDataBase(const std::string& filePath, #endif err->append("."); - if (intMax.size() > 0) { + if (!intMax.empty()) { err->append(" " + intMax); } - if (intGeo.size() > 0) { + if (!intGeo.empty()) { err->append(" " + intGeo); } return false; diff --git a/src/variables/web_app_id.h b/src/variables/web_app_id.h index d5f1aa54..47cf4229 100644 --- a/src/variables/web_app_id.h +++ b/src/variables/web_app_id.h @@ -38,7 +38,6 @@ class WebAppId : public Variable { void evaluate(Transaction *transaction, RuleWithActions *rule, std::vector *l) override { - const std::string name("WEBAPPID"); const std::string rname = transaction->m_rules->m_secWebAppId.m_value; l->push_back(new VariableValue(&m_name, &rname)); } diff --git a/test/cppcheck_suppressions.txt b/test/cppcheck_suppressions.txt index 0336b6aa..8d3a5874 100644 --- a/test/cppcheck_suppressions.txt +++ b/test/cppcheck_suppressions.txt @@ -51,6 +51,9 @@ duplicateBranch:src/request_body_processor/multipart.cc:91 syntaxError:src/transaction.cc:62 noConstructor:src/variables/variable.h:152 duplicateBranch:src/request_body_processor/multipart.cc:93 +knownConditionTrueFalse:src/utils/geo_lookup.cc:94 +knownConditionTrueFalse:src/utils/geo_lookup.cc:98 +danglingTempReference:src/modsecurity.cc:204 noExplicitConstructor:seclang-parser.hh @@ -61,3 +64,4 @@ preprocessorErrorDirective funcArgNamesDifferent unmatchedSuppression missingInclude +