Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/checkleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "token.h"
#include "tokenize.h"

#include <array>
#include <iostream>
#include <list>
#include <memory>
Expand All @@ -52,8 +53,8 @@ static const CWE CWE415(415U);
static const int NEW_ARRAY = -2;
static const int NEW = -1;

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

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

template<std::size_t N>
static bool isVarTokComparison(const Token * tok, const Token ** vartok,
const std::vector<std::pair<std::string, std::string>>& ops)
const std::array<std::pair<std::string, std::string>, N>& ops)
{
for (const auto & op : ops) {
if (astIsVariableComparison(tok, op.first, op.second, vartok))
Expand Down
3 changes: 2 additions & 1 deletion lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "suppressions.h"

#include <algorithm>
#include <array>
#include <cstddef>
#include <iterator> // back_inserter
#include <memory>
Expand Down Expand Up @@ -417,7 +418,7 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
if (cmdtok->str() == "ifndef")
ifndef = true;
else {
const std::vector<std::string> match{"if", "!", "defined", "(", config, ")"};
const std::array<std::string, 6> match{"if", "!", "defined", "(", config, ")"};
int i = 0;
ifndef = true;
for (const simplecpp::Token *t = cmdtok; i < match.size(); t = t->next) {
Expand Down
3 changes: 2 additions & 1 deletion lib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "config.h"

#include <algorithm>
#include <array>
#include <cstddef>
#include <initializer_list>
#include <string>
Expand Down Expand Up @@ -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<std::string> suffixes{"", "u8", "u", "U", "L"};
static const std::array<std::string, 5> suffixes{"", "u8", "u", "U", "L"};
for (const std::string & p: suffixes) {
if (isPrefixStringCharLiteral(str, q, p))
return true;
Expand Down
3 changes: 2 additions & 1 deletion tools/dmake.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// Generate Makefile for cppcheck

#include <algorithm>
#include <array>
#include <fstream> // IWYU pragma: keep
#include <iostream>
#include <string>
Expand Down Expand Up @@ -55,7 +56,7 @@ static std::string objfiles(const std::vector<std::string> &files)

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

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