Skip to content

Commit f762aff

Browse files
committed
Small refactoring: replace NULL by nullptr, remove redundant static keyword, Tokenizer::setVarId() uses const variable 'notstart'
1 parent 9a42f52 commit f762aff

12 files changed

Lines changed: 41 additions & 45 deletions

cli/cppcheckexecutor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,10 @@ namespace {
580580
hThread,
581581
&stack,
582582
&context,
583-
NULL,
583+
nullptr,
584584
pSymFunctionTableAccess64,
585585
pSymGetModuleBase64,
586-
NULL
586+
nullptr
587587
);
588588
if (!result) // official end...
589589
break;
@@ -748,15 +748,15 @@ int CppCheckExecutor::check_wrapper(CppCheck& cppcheck, int argc, const char* co
748748
segv_stack.ss_sp = mytstack;
749749
segv_stack.ss_flags = 0;
750750
segv_stack.ss_size = MYSTACKSIZE;
751-
sigaltstack(&segv_stack, NULL);
751+
sigaltstack(&segv_stack, nullptr);
752752

753753
// install signal handler
754754
struct sigaction act;
755755
memset(&act, 0, sizeof(act));
756756
act.sa_flags=SA_SIGINFO|SA_ONSTACK;
757757
act.sa_sigaction=CppcheckSignalHandler;
758758
for (std::map<int, std::string>::const_iterator sig=listofsignals.begin(); sig!=listofsignals.end(); ++sig) {
759-
sigaction(sig->first, &act, NULL);
759+
sigaction(sig->first, &act, nullptr);
760760
}
761761
return check_internal(cppcheck, argc, argv);
762762
#else
@@ -912,7 +912,7 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
912912
return;
913913

914914
// Report progress messages every 10 seconds
915-
const std::time_t time2 = std::time(NULL);
915+
const std::time_t time2 = std::time(nullptr);
916916
if (time2 >= (time1 + 10)) {
917917
time1 = time2;
918918

cli/filelister.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,11 @@ std::string FileLister::getAbsolutePath(const std::string& path)
176176

177177
#ifdef PATH_MAX
178178
char buf[PATH_MAX];
179-
if (realpath(path.c_str(), buf) != NULL)
179+
if (realpath(path.c_str(), buf) != nullptr)
180180
absolute_path = buf;
181181
#else
182182
char *dynamic_buf;
183-
if ((dynamic_buf = realpath(path.c_str(), NULL)) != NULL) {
183+
if ((dynamic_buf = realpath(path.c_str(), nullptr)) != nullptr) {
184184
absolute_path = dynamic_buf;
185185
free(dynamic_buf);
186186
}

cli/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int main(int argc, char* argv[])
126126

127127
CppCheckExecutor exec;
128128
#ifdef _WIN32
129-
GetModuleFileNameA(NULL, exename, sizeof(exename)/sizeof(exename[0])-1);
129+
GetModuleFileNameA(nullptr, exename, sizeof(exename)/sizeof(exename[0])-1);
130130
argv[0] = exename;
131131
#endif
132132

cli/threadexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ unsigned int ThreadExecutor::check()
238238
struct timeval tv; // for every second polling of load average condition
239239
tv.tv_sec = 1;
240240
tv.tv_usec = 0;
241-
int r = select(*std::max_element(rpipes.begin(), rpipes.end()) + 1, &rfds, NULL, NULL, &tv);
241+
int r = select(*std::max_element(rpipes.begin(), rpipes.end()) + 1, &rfds, nullptr, nullptr, &tv);
242242

243243
if (r > 0) {
244244
std::list<int>::iterator rp = rpipes.begin();

lib/checkclass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ bool CheckClass::isConstMemberFunc(const Scope *scope, const Token *tok) const
18471847

18481848
namespace {
18491849
// The container contains the STL types whose operator[] is not a const.
1850-
static const std::set<std::string> stl_containers_not_const = make_container< std::set<std::string> >() << "map" << "unordered_map";
1850+
const std::set<std::string> stl_containers_not_const = make_container< std::set<std::string> >() << "map" << "unordered_map";
18511851
}
18521852

18531853
bool CheckClass::checkConstFunc(const Scope *scope, const Function *func, bool& memberAccessed) const

lib/checkio.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ struct Filepointer {
9595
};
9696

9797
namespace {
98-
static const std::set<std::string> whitelist = make_container< std::set<std::string> > ()
99-
<< "clearerr" << "feof" << "ferror" << "fgetpos" << "ftell" << "setbuf" << "setvbuf" << "ungetc" << "ungetwc";
98+
const std::set<std::string> whitelist = make_container< std::set<std::string> > ()
99+
<< "clearerr" << "feof" << "ferror" << "fgetpos" << "ftell" << "setbuf" << "setvbuf" << "ungetc" << "ungetwc";
100100
}
101101

102102
void CheckIO::checkFileUsage()
@@ -1552,8 +1552,8 @@ CheckIO::ArgumentInfo::~ArgumentInfo()
15521552
}
15531553

15541554
namespace {
1555-
static const std::set<std::string> stl_vector = make_container< std::set<std::string> >() << "array" << "vector";
1556-
static const std::set<std::string> stl_string = make_container< std::set<std::string> >() << "string" << "u16string" << "u32string" << "wstring";
1555+
const std::set<std::string> stl_vector = make_container< std::set<std::string> >() << "array" << "vector";
1556+
const std::set<std::string> stl_string = make_container< std::set<std::string> >() << "string" << "u16string" << "u32string" << "wstring";
15571557
}
15581558

15591559
bool CheckIO::ArgumentInfo::isStdVectorOrString()
@@ -1614,7 +1614,7 @@ bool CheckIO::ArgumentInfo::isStdVectorOrString()
16141614
}
16151615

16161616
namespace {
1617-
static const std::set<std::string> stl_container = make_container< std::set<std::string> >() <<
1617+
const std::set<std::string> stl_container = make_container< std::set<std::string> >() <<
16181618
"array" << "bitset" << "deque" << "forward_list" <<
16191619
"hash_map" << "hash_multimap" << "hash_set" <<
16201620
"list" << "map" << "multimap" << "multiset" <<

lib/checknullpointer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void CheckNullPointer::parseFunctionCall(const Token &tok, std::list<const Token
138138
}
139139

140140
namespace {
141-
static const std::set<std::string> stl_stream = make_container< std::set<std::string> >() <<
141+
const std::set<std::string> stl_stream = make_container< std::set<std::string> >() <<
142142
"fstream" << "ifstream" << "iostream" << "istream" <<
143143
"istringstream" << "ofstream" << "ostream" << "ostringstream" <<
144144
"stringstream" << "wistringstream" << "wostringstream" << "wstringstream";
@@ -376,7 +376,7 @@ void CheckNullPointer::nullPointer()
376376
}
377377

378378
namespace {
379-
static const std::set<std::string> stl_istream = make_container< std::set<std::string> >() <<
379+
const std::set<std::string> stl_istream = make_container< std::set<std::string> >() <<
380380
"fstream" << "ifstream" << "iostream" << "istream" <<
381381
"istringstream" << "stringstream" << "wistringstream" << "wstringstream";
382382
}

lib/checkstl.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,16 @@ namespace {
254254
const std::set<std::string> algorithm1x1 = make_container< std::set<std::string> >() // func(begin1 << x << end1
255255
<< "inplace_merge" << "nth_element" << "partial_sort" << "rotate" << "rotate_copy";
256256

257-
static const std::string iteratorBeginFuncPattern = "begin|cbegin|rbegin|crbegin";
258-
static const std::string iteratorEndFuncPattern = "end|cend|rend|crend";
257+
const std::string iteratorBeginFuncPattern = "begin|cbegin|rbegin|crbegin";
258+
const std::string iteratorEndFuncPattern = "end|cend|rend|crend";
259259

260-
static const std::string pattern1x1_1 = "%name% . " + iteratorBeginFuncPattern + " ( ) , ";
261-
static const std::string pattern1x1_2 = "%name% . " + iteratorEndFuncPattern + " ( ) ,|)";
262-
static const std::string pattern2 = pattern1x1_1 + pattern1x1_2;
260+
const std::string pattern1x1_1 = "%name% . " + iteratorBeginFuncPattern + " ( ) , ";
261+
const std::string pattern1x1_2 = "%name% . " + iteratorEndFuncPattern + " ( ) ,|)";
262+
const std::string pattern2 = pattern1x1_1 + pattern1x1_2;
263263
}
264264

265265
void CheckStl::mismatchingContainers()
266266
{
267-
268267
// Check if different containers are used in various calls of standard functions
269268
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
270269
const std::size_t functions = symbolDatabase->functionScopes.size();
@@ -593,8 +592,6 @@ void CheckStl::invalidPointerError(const Token *tok, const std::string &func, co
593592
}
594593

595594

596-
597-
598595
void CheckStl::stlBoundaries()
599596
{
600597
const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
@@ -924,7 +921,7 @@ static bool isLocal(const Token *tok)
924921
}
925922

926923
namespace {
927-
static const std::set<std::string> stl_string_stream = make_container< std::set<std::string> >() <<
924+
const std::set<std::string> stl_string_stream = make_container< std::set<std::string> >() <<
928925
"istringstream" << "ostringstream" << "stringstream" << "wstringstream" ;
929926
}
930927

@@ -1115,7 +1112,7 @@ void CheckStl::checkAutoPointer()
11151112
{
11161113
std::set<unsigned int> autoPtrVarId;
11171114
std::map<unsigned int, const std::string> mallocVarId; // variables allocated by the malloc-like function
1118-
static const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
1115+
const char STL_CONTAINER_LIST[] = "array|bitset|deque|list|forward_list|map|multimap|multiset|priority_queue|queue|set|stack|vector|hash_map|hash_multimap|hash_set|unordered_map|unordered_multimap|unordered_set|unordered_multiset|basic_string";
11191116
const int malloc = _settings->library.alloc("malloc"); // allocation function, which are not compatible with auto_ptr
11201117
const bool printStyle = _settings->isEnabled("style");
11211118

@@ -1229,7 +1226,7 @@ void CheckStl::autoPointerMallocError(const Token *tok, const std::string& alloc
12291226
}
12301227

12311228
namespace {
1232-
static const std::set<std::string> stl_containers_with_empty_and_clear = make_container< std::set<std::string> >() <<
1229+
const std::set<std::string> stl_containers_with_empty_and_clear = make_container< std::set<std::string> >() <<
12331230
"deque" << "forward_list" << "list" <<
12341231
"map" << "multimap" << "multiset" << "set" << "string" <<
12351232
"unordered_map" << "unordered_multimap" << "unordered_multiset" <<
@@ -1389,7 +1386,6 @@ void CheckStl::dereferenceInvalidIteratorError(const Token* deref, const std::st
13891386

13901387

13911388

1392-
13931389
void CheckStl::readingEmptyStlContainer_parseUsage(const Token* tok, const Library::Container* container, std::map<unsigned int, const Library::Container*>& empty, bool noerror)
13941390
{
13951391
// Check for various conditions for the way stl containers and variables can be used

lib/checkuninitvar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,12 +1067,12 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str
10671067
}
10681068

10691069
// is this a function call?
1070-
ftok = ftok ? ftok->previous() : NULL;
1070+
ftok = ftok ? ftok->previous() : nullptr;
10711071
if (Token::Match(ftok, "%name% (")) {
10721072
// check how function handle uninitialized data arguments..
10731073
const Function *function = ftok->function();
1074-
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : NULL;
1075-
const Token *argStart = arg ? arg->typeStartToken() : NULL;
1074+
const Variable *arg = function ? function->getArgumentVar(argumentNumber) : nullptr;
1075+
const Token *argStart = arg ? arg->typeStartToken() : nullptr;
10761076
while (argStart && argStart->previous() && argStart->previous()->isName())
10771077
argStart = argStart->previous();
10781078
if (Token::Match(argStart, "const struct| %type% * const| %name% [,)]"))

lib/path.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ std::string Path::getAbsoluteFilePath(const std::string& filePath)
249249
if (_fullpath(absolute, filePath.c_str(), _MAX_PATH))
250250
absolute_path = absolute;
251251
#elif defined(__linux__) || defined(__sun) || defined(__hpux) || defined(__GNUC__)
252-
char * absolute = realpath(filePath.c_str(), NULL);
252+
char * absolute = realpath(filePath.c_str(), nullptr);
253253
if (absolute)
254254
absolute_path = absolute;
255255
free(absolute);

0 commit comments

Comments
 (0)