Skip to content

Commit fb5c2d4

Browse files
committed
use nullptr in lib/checkother.cpp
1 parent 720bd48 commit fb5c2d4

5 files changed

Lines changed: 35 additions & 35 deletions

File tree

lib/checkother.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ static bool isConstExpression(const Token *tok, const std::set<std::string> &con
6464

6565
static bool isSameExpression(const Token *tok1, const Token *tok2, const std::set<std::string> &constFunctions)
6666
{
67-
if (tok1 == NULL && tok2 == NULL)
67+
if (tok1 == nullptr && tok2 == nullptr)
6868
return true;
69-
if (tok1 == NULL || tok2 == NULL)
69+
if (tok1 == nullptr || tok2 == nullptr)
7070
return false;
7171
if (tok1->str() != tok2->str())
7272
return false;
@@ -949,7 +949,7 @@ void CheckOther::checkSwitchCaseFallThrough()
949949
for (const Token *tok2 = i->classStart; tok2 != i->classEnd; tok2 = tok2->next()) {
950950
if (Token::simpleMatch(tok2, "if (")) {
951951
tok2 = tok2->next()->link()->next();
952-
if (tok2->link() == NULL) {
952+
if (tok2->link() == nullptr) {
953953
std::ostringstream errmsg;
954954
errmsg << "unmatched if in switch: " << tok2->linenr();
955955
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
@@ -961,7 +961,7 @@ void CheckOther::checkSwitchCaseFallThrough()
961961
tok2 = tok2->next()->link()->next();
962962
// skip over "do { } while ( ) ;" case
963963
if (tok2->str() == "{") {
964-
if (tok2->link() == NULL) {
964+
if (tok2->link() == nullptr) {
965965
std::ostringstream errmsg;
966966
errmsg << "unmatched while in switch: " << tok2->linenr();
967967
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
@@ -972,7 +972,7 @@ void CheckOther::checkSwitchCaseFallThrough()
972972
justbreak = false;
973973
} else if (Token::simpleMatch(tok2, "do {")) {
974974
tok2 = tok2->next();
975-
if (tok2->link() == NULL) {
975+
if (tok2->link() == nullptr) {
976976
std::ostringstream errmsg;
977977
errmsg << "unmatched do in switch: " << tok2->linenr();
978978
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
@@ -982,7 +982,7 @@ void CheckOther::checkSwitchCaseFallThrough()
982982
justbreak = false;
983983
} else if (Token::simpleMatch(tok2, "for (")) {
984984
tok2 = tok2->next()->link()->next();
985-
if (tok2->link() == NULL) {
985+
if (tok2->link() == nullptr) {
986986
std::ostringstream errmsg;
987987
errmsg << "unmatched for in switch: " << tok2->linenr();
988988
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
@@ -1012,7 +1012,7 @@ void CheckOther::checkSwitchCaseFallThrough()
10121012
if (tok2->next()->str() == "else") {
10131013
tok2 = tok2->tokAt(2);
10141014
ifnest.pop();
1015-
if (tok2->link() == NULL) {
1015+
if (tok2->link() == nullptr) {
10161016
std::ostringstream errmsg;
10171017
errmsg << "unmatched if in switch: " << tok2->linenr();
10181018
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
@@ -1530,7 +1530,7 @@ void CheckOther::invalidFunctionUsage()
15301530
sprintfOverlappingDataError(tok2, tok2->str());
15311531
break;
15321532
}
1533-
} while (NULL != (tok2 = tok2->nextArgument()));
1533+
} while (nullptr != (tok2 = tok2->nextArgument()));
15341534
}
15351535
}
15361536

@@ -2198,7 +2198,7 @@ void CheckOther::checkZeroDivision()
21982198
// Value flow..
21992199
const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL);
22002200
if (value) {
2201-
if (value->condition == NULL)
2201+
if (value->condition == nullptr)
22022202
zerodivError(tok);
22032203
else if (_settings->isEnabled("warning"))
22042204
zerodivcondError(value->condition,tok);
@@ -2628,7 +2628,7 @@ void CheckOther::checkInvalidFree()
26282628
// if it is later used to free memory
26292629
else if (Token::Match(tok, "%var% (")) {
26302630
const Token* tok2 = Token::findmatch(tok->next(), "%var%", tok->linkAt(1));
2631-
while (tok2 != NULL) {
2631+
while (tok2 != nullptr) {
26322632
allocatedVariables.erase(tok2->varId());
26332633
tok2 = Token::findmatch(tok2->next(), "%var%", tok->linkAt(1));
26342634
}
@@ -2698,7 +2698,7 @@ void CheckOther::checkDoubleFree()
26982698
else if (tok->str() == "}" && tok->link() && tok->link()->previous() &&
26992699
tok->link()->linkAt(-1) &&
27002700
Token::Match(tok->link()->linkAt(-1)->previous(), "while|for") &&
2701-
Token::findmatch(tok->link()->linkAt(-1), "break|continue ;", tok) != NULL) {
2701+
Token::findmatch(tok->link()->linkAt(-1), "break|continue ;", tok) != nullptr) {
27022702
freedVariables.clear();
27032703
closeDirVariables.clear();
27042704
}
@@ -2855,23 +2855,23 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
28552855
return;
28562856

28572857
const Token *tok = _tokenizer->tokens();
2858-
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %str% , %str% ")) != NULL) {
2858+
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %str% , %str% ")) != nullptr) {
28592859
const std::string &str1 = tok->strAt(2);
28602860
const std::string &str2 = tok->strAt(4);
28612861
alwaysTrueFalseStringCompareError(tok, str1, str2);
28622862
tok = tok->tokAt(5);
28632863
}
28642864

28652865
tok = _tokenizer->tokens();
2866-
while (tok && (tok = Token::findmatch(tok, "QString :: compare ( %str% , %str% )")) != NULL) {
2866+
while (tok && (tok = Token::findmatch(tok, "QString :: compare ( %str% , %str% )")) != nullptr) {
28672867
const std::string &str1 = tok->strAt(4);
28682868
const std::string &str2 = tok->strAt(6);
28692869
alwaysTrueFalseStringCompareError(tok, str1, str2);
28702870
tok = tok->tokAt(7);
28712871
}
28722872

28732873
tok = _tokenizer->tokens();
2874-
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %var% , %var% ")) != NULL) {
2874+
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %var% , %var% ")) != nullptr) {
28752875
const std::string &str1 = tok->strAt(2);
28762876
const std::string &str2 = tok->strAt(4);
28772877
if (str1 == str2)
@@ -2880,7 +2880,7 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
28802880
}
28812881

28822882
tok = _tokenizer->tokens();
2883-
while (tok && (tok = Token::findmatch(tok, "!!+ %str% ==|!= %str% !!+")) != NULL) {
2883+
while (tok && (tok = Token::findmatch(tok, "!!+ %str% ==|!= %str% !!+")) != nullptr) {
28842884
const std::string &str1 = tok->strAt(1);
28852885
const std::string &str2 = tok->strAt(3);
28862886
alwaysTrueFalseStringCompareError(tok, str1, str2);
@@ -3318,7 +3318,7 @@ void CheckOther::oppositeInnerCondition()
33183318

33193319
if (scope->classDef->strAt(6) == "{") {
33203320

3321-
const char *oppositeCondition = NULL;
3321+
const char *oppositeCondition = nullptr;
33223322

33233323
if (scope->classDef->strAt(3) == "==")
33243324
oppositeCondition = "if ( %any% !=|<|>|<=|>= %any% )";
@@ -3388,13 +3388,13 @@ void CheckOther::checkVarFuncNullUB()
33883388
++argnr;
33893389
ftok = ftok->previous();
33903390
}
3391-
ftok = ftok ? ftok->previous() : NULL;
3391+
ftok = ftok ? ftok->previous() : nullptr;
33923392
if (ftok && ftok->isName()) {
33933393
// If this is a variadic function then report error
33943394
const Function *f = ftok->function();
33953395
if (f && f->argCount() <= argnr) {
33963396
const Token *tok2 = f->argDef;
3397-
tok2 = tok2 ? tok2->link() : NULL; // goto ')'
3397+
tok2 = tok2 ? tok2->link() : nullptr; // goto ')'
33983398
if (Token::simpleMatch(tok2->tokAt(-3), ". . ."))
33993399
varFuncNullUBError(tok);
34003400
}

lib/checkstl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ void CheckStl::iterators()
133133
if (container && tok2->varId() != container->declarationId()) {
134134
// skip error message if container is a set..
135135
const Variable *variableInfo = tok2->variable();
136-
const Token *decltok = variableInfo ? variableInfo->typeStartToken() : NULL;
136+
const Token *decltok = variableInfo ? variableInfo->typeStartToken() : nullptr;
137137

138138
if (Token::simpleMatch(decltok, "std :: set"))
139139
continue; // No warning
@@ -434,7 +434,7 @@ class EraseCheckLoop : public ExecutionPath {
434434
// check if there is a "it = ints.erase(it);" pattern. if so
435435
// the it is not invalidated.
436436
const Token *token = &tok;
437-
while (NULL != (token = token ? token->previous() : 0)) {
437+
while (nullptr != (token = token ? token->previous() : 0)) {
438438
if (Token::Match(token, "[;{}]"))
439439
break;
440440
else if (token->str() == "=")
@@ -506,7 +506,7 @@ void CheckStl::erase()
506506
if (Token::Match(tok2, "; %var% !=")) {
507507
// Get declaration token for var..
508508
const Variable *variableInfo = tok2->next()->variable();
509-
const Token *decltok = variableInfo ? variableInfo->typeEndToken() : NULL;
509+
const Token *decltok = variableInfo ? variableInfo->typeEndToken() : nullptr;
510510

511511
// Is variable an iterator?
512512
bool isIterator = false;

lib/checkuninitvar.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class UninitVar : public ExecutionPath {
368368
*/
369369
static void parserhs(const Token *tok2, std::list<ExecutionPath *> &checks) {
370370
// check variable usages in rhs/index
371-
while (NULL != (tok2 = tok2->next())) {
371+
while (nullptr != (tok2 = tok2->next())) {
372372
if (Token::Match(tok2, "[;)=]"))
373373
break;
374374
if (Token::Match(tok2, "%var% ("))
@@ -713,7 +713,7 @@ class UninitVar : public ExecutionPath {
713713
if (Token::Match(tok2->tokAt(-2), "[(,] *") || Token::Match(tok2->next(), ". %var%")) {
714714
// find function call..
715715
const Token *functionCall = tok2;
716-
while (NULL != (functionCall = functionCall ? functionCall->previous() : 0)) {
716+
while (nullptr != (functionCall = functionCall ? functionCall->previous() : 0)) {
717717
if (functionCall->str() == "(")
718718
break;
719719
if (functionCall->str() == ")")
@@ -1097,7 +1097,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
10971097
}
10981098
if (stdtype || i->isPointer()) {
10991099
bool alloc = false;
1100-
checkScopeForVariable(scope, tok, *i, NULL, NULL, &alloc, "");
1100+
checkScopeForVariable(scope, tok, *i, nullptr, nullptr, &alloc, "");
11011101
}
11021102
if (Token::Match(i->typeStartToken(), "struct %type% *| %var% ;"))
11031103
checkStruct(scope, tok, *i);
@@ -1115,7 +1115,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
11151115
checkStruct(scope, tok, *arg);
11161116
else if (arg->typeStartToken()->isStandardType()) {
11171117
bool alloc = false;
1118-
checkScopeForVariable(scope, tok->next(), *arg, NULL, NULL, &alloc, "");
1118+
checkScopeForVariable(scope, tok->next(), *arg, nullptr, nullptr, &alloc, "");
11191119
}
11201120
}
11211121
}
@@ -1156,7 +1156,7 @@ void CheckUninitVar::checkStruct(const Scope* scope, const Token *tok, const Var
11561156
const Token *tok2 = tok;
11571157
if (tok->str() == "}")
11581158
tok2 = tok2->next();
1159-
checkScopeForVariable(scope, tok2, structvar, NULL, NULL, &alloc, var.name());
1159+
checkScopeForVariable(scope, tok2, structvar, nullptr, nullptr, &alloc, var.name());
11601160
}
11611161
}
11621162
}
@@ -1239,7 +1239,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
12391239

12401240
// Unconditional inner scope..
12411241
if (tok->str() == "{" && Token::Match(tok->previous(), "[;{}]")) {
1242-
if (checkScopeForVariable(scope, tok->next(), var, possibleInit, NULL, alloc, membervar))
1242+
if (checkScopeForVariable(scope, tok->next(), var, possibleInit, nullptr, alloc, membervar))
12431243
return true;
12441244
tok = tok->link();
12451245
continue;
@@ -1330,7 +1330,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
13301330

13311331
bool possibleInitElse(number_of_if > 0 || suppressErrors);
13321332
bool noreturnElse = false;
1333-
const bool initelse = !alwaysTrue && checkScopeForVariable(scope, tok->next(), var, &possibleInitElse, NULL, alloc, membervar);
1333+
const bool initelse = !alwaysTrue && checkScopeForVariable(scope, tok->next(), var, &possibleInitElse, nullptr, alloc, membervar);
13341334

13351335
std::map<unsigned int, int> varValueElse;
13361336
if (!alwaysTrue && !initelse && !noreturnElse) {
@@ -1479,7 +1479,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
14791479
tok = tok->next();
14801480
}
14811481

1482-
return bool(noreturn==NULL);
1482+
return bool(noreturn==nullptr);
14831483
}
14841484

14851485
// variable is seen..
@@ -1564,7 +1564,7 @@ bool CheckUninitVar::checkIfForWhileHead(const Token *startparentheses, const Va
15641564

15651565
bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const bool alloc, const std::string &membervar, const bool suppressErrors)
15661566
{
1567-
const Token *usetok = NULL;
1567+
const Token *usetok = nullptr;
15681568

15691569
assert(tok->str() == "{");
15701570

@@ -1643,7 +1643,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, bool alloc,
16431643
{
16441644
bool rhs = false;
16451645
unsigned int indent = 0;
1646-
while (NULL != (tok = tok->next())) {
1646+
while (nullptr != (tok = tok->next())) {
16471647
if (tok->str() == "=")
16481648
rhs = true;
16491649
else if (rhs && tok->varId() == var.declarationId()) {

lib/checkunusedvar.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ void Variables::leaveScope(bool insideLoop)
381381
for (std::set<unsigned int>::const_iterator readIter = currentVarReadInScope.begin();
382382
readIter != currentVarReadInScope.end();
383383
++readIter) {
384-
read(*readIter, NULL);
384+
read(*readIter, nullptr);
385385
}
386386
}
387387

@@ -1192,7 +1192,7 @@ void CheckUnusedVar::checkStructMemberUsage()
11921192
if (!structname.empty()) {
11931193
const std::string pattern1(structname + " %var% ;");
11941194
const Token *tok2 = tok;
1195-
while (NULL != (tok2 = Token::findmatch(tok2->next(), pattern1.c_str()))) {
1195+
while (nullptr != (tok2 = Token::findmatch(tok2->next(), pattern1.c_str()))) {
11961196
if (Token::simpleMatch(tok2->tokAt(3), (tok2->strAt(1) + " = {").c_str())) {
11971197
structname.clear();
11981198
break;

lib/cppcheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
451451

452452
const char *error = 0;
453453
int erroffset = 0;
454-
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,NULL);
454+
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,nullptr);
455455
if (!re) {
456456
if (error) {
457457
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
@@ -467,7 +467,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
467467

468468
int pos = 0;
469469
int ovector[30];
470-
while (pos < (int)str.size() && 0 <= pcre_exec(re, NULL, str.c_str(), (int)str.size(), pos, 0, ovector, 30)) {
470+
while (pos < (int)str.size() && 0 <= pcre_exec(re, nullptr, str.c_str(), (int)str.size(), pos, 0, ovector, 30)) {
471471
unsigned int pos1 = (unsigned int)ovector[0];
472472
unsigned int pos2 = (unsigned int)ovector[1];
473473

0 commit comments

Comments
 (0)