Skip to content

Commit 3722011

Browse files
committed
replaced static const std::vector containers with std::array
1 parent 363dd30 commit 3722011

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/checkleakautovar.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "token.h"
3333
#include "tokenize.h"
3434

35+
#include <array>
3536
#include <iostream>
3637
#include <list>
3738
#include <memory>
@@ -52,8 +53,8 @@ static const CWE CWE415(415U);
5253
static const int NEW_ARRAY = -2;
5354
static const int NEW = -1;
5455

55-
static const std::vector<std::pair<std::string, std::string>> alloc_failed_conds {{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}};
56-
static const std::vector<std::pair<std::string, std::string>> alloc_success_conds {{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}};
56+
static const std::array<std::pair<std::string, std::string>, 4> alloc_failed_conds {{{"==", "0"}, {"<", "0"}, {"==", "-1"}, {"<=", "-1"}}};
57+
static const std::array<std::pair<std::string, std::string>, 4> alloc_success_conds {{{"!=", "0"}, {">", "0"}, {"!=", "-1"}, {">=", "0"}}};
5758

5859
/**
5960
* @brief Is variable type some class with automatic deallocation?
@@ -77,8 +78,9 @@ static bool isAutoDealloc(const Variable *var)
7778
return true;
7879
}
7980

81+
template <std::size_t N>
8082
static bool isVarTokComparison(const Token * tok, const Token ** vartok,
81-
const std::vector<std::pair<std::string, std::string>>& ops)
83+
const std::array<std::pair<std::string, std::string>, N>& ops)
8284
{
8385
for (const auto & op : ops) {
8486
if (astIsVariableComparison(tok, op.first, op.second, vartok))

lib/utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "config.h"
2525

2626
#include <algorithm>
27+
#include <array>
2728
#include <cstddef>
2829
#include <initializer_list>
2930
#include <string>
@@ -97,7 +98,7 @@ inline static bool isPrefixStringCharLiteral(const std::string &str, char q, con
9798

9899
inline static bool isStringCharLiteral(const std::string &str, char q)
99100
{
100-
static const std::vector<std::string> suffixes{"", "u8", "u", "U", "L"};
101+
static const std::array<std::string, 5> suffixes{{"", "u8", "u", "U", "L"}};
101102
for (const std::string & p: suffixes) {
102103
if (isPrefixStringCharLiteral(str, q, p))
103104
return true;

tools/dmake.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// Generate Makefile for cppcheck
2020

2121
#include <algorithm>
22+
#include <array>
2223
#include <fstream> // IWYU pragma: keep
2324
#include <iostream>
2425
#include <string>
@@ -55,7 +56,7 @@ static std::string objfiles(const std::vector<std::string> &files)
5556

5657
static void getDeps(const std::string &filename, std::vector<std::string> &depfiles)
5758
{
58-
static const std::vector<std::string> externalfolders{"externals", "externals/picojson", "externals/simplecpp", "externals/tinyxml2" };
59+
static const std::array<std::string, 4> externalfolders{{"externals", "externals/picojson", "externals/simplecpp", "externals/tinyxml2"}};
5960

6061
// Is the dependency already included?
6162
if (std::find(depfiles.begin(), depfiles.end(), filename) != depfiles.end())

0 commit comments

Comments
 (0)