From d6f1d7bb23ac67c12767364d498cf3fbecced802 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 27 Sep 2022 20:06:15 +0200 Subject: [PATCH] replaced `static const`/fixed `std::vector` containers with `std::array` (#4440) --- lib/checkleakautovar.cpp | 8 +++++--- lib/preprocessor.cpp | 3 ++- lib/utils.h | 3 ++- tools/dmake.cpp | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/checkleakautovar.cpp b/lib/checkleakautovar.cpp index 06efba232..ec71eb1c5 100644 --- a/lib/checkleakautovar.cpp +++ b/lib/checkleakautovar.cpp @@ -32,6 +32,7 @@ #include "token.h" #include "tokenize.h" +#include #include #include #include @@ -52,8 +53,8 @@ static const CWE CWE415(415U); static const int NEW_ARRAY = -2; static const int NEW = -1; -static const std::vector> alloc_failed_conds {{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}; -static const std::vector> alloc_success_conds {{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}; +static const std::array, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}}; +static const std::array, 4> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}}; /** * @brief Is variable type some class with automatic deallocation? @@ -77,8 +78,9 @@ static bool isAutoDealloc(const Variable *var) return true; } +template static bool isVarTokComparison(const Token * tok, const Token ** vartok, - const std::vector>& ops) + const std::array, N>& ops) { for (const auto & op : ops) { if (astIsVariableComparison(tok, op.first, op.second, vartok)) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 860402ef1..e035d8b51 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -28,6 +28,7 @@ #include "suppressions.h" #include +#include #include #include // back_inserter #include @@ -417,7 +418,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set if (cmdtok->str() == "ifndef") ifndef = true; else { - const std::vector match{"if", "!", "defined", "(", config, ")"}; + const std::array match{"if", "!", "defined", "(", config, ")"}; int i = 0; ifndef = true; for (const simplecpp::Token *t = cmdtok; i < match.size(); t = t->next) { diff --git a/lib/utils.h b/lib/utils.h index 173b91b8d..c8e7e6816 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -24,6 +24,7 @@ #include "config.h" #include +#include #include #include #include @@ -97,7 +98,7 @@ inline static bool isPrefixStringCharLiteral(const std::string &str, char q, con inline static bool isStringCharLiteral(const std::string &str, char q) { - static const std::vector suffixes{"", "u8", "u", "U", "L"}; + static const std::array suffixes{"", "u8", "u", "U", "L"}; for (const std::string & p: suffixes) { if (isPrefixStringCharLiteral(str, q, p)) return true; diff --git a/tools/dmake.cpp b/tools/dmake.cpp index c80346ec4..ee7bc5118 100644 --- a/tools/dmake.cpp +++ b/tools/dmake.cpp @@ -19,6 +19,7 @@ // Generate Makefile for cppcheck #include +#include #include // IWYU pragma: keep #include #include @@ -55,7 +56,7 @@ static std::string objfiles(const std::vector &files) static void getDeps(const std::string &filename, std::vector &depfiles) { - static const std::vector externalfolders{"externals", "externals/picojson", "externals/simplecpp", "externals/tinyxml2" }; + static const std::array externalfolders{"externals", "externals/picojson", "externals/simplecpp", "externals/tinyxml2"}; // Is the dependency already included? if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end())