use nullptr in lib/checkother.cpp
This commit is contained in:
parent
720bd48a98
commit
fb5c2d4b48
|
@ -64,9 +64,9 @@ static bool isConstExpression(const Token *tok, const std::set<std::string> &con
|
|||
|
||||
static bool isSameExpression(const Token *tok1, const Token *tok2, const std::set<std::string> &constFunctions)
|
||||
{
|
||||
if (tok1 == NULL && tok2 == NULL)
|
||||
if (tok1 == nullptr && tok2 == nullptr)
|
||||
return true;
|
||||
if (tok1 == NULL || tok2 == NULL)
|
||||
if (tok1 == nullptr || tok2 == nullptr)
|
||||
return false;
|
||||
if (tok1->str() != tok2->str())
|
||||
return false;
|
||||
|
@ -949,7 +949,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
for (const Token *tok2 = i->classStart; tok2 != i->classEnd; tok2 = tok2->next()) {
|
||||
if (Token::simpleMatch(tok2, "if (")) {
|
||||
tok2 = tok2->next()->link()->next();
|
||||
if (tok2->link() == NULL) {
|
||||
if (tok2->link() == nullptr) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "unmatched if in switch: " << tok2->linenr();
|
||||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
|
@ -961,7 +961,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
tok2 = tok2->next()->link()->next();
|
||||
// skip over "do { } while ( ) ;" case
|
||||
if (tok2->str() == "{") {
|
||||
if (tok2->link() == NULL) {
|
||||
if (tok2->link() == nullptr) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "unmatched while in switch: " << tok2->linenr();
|
||||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
|
@ -972,7 +972,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
justbreak = false;
|
||||
} else if (Token::simpleMatch(tok2, "do {")) {
|
||||
tok2 = tok2->next();
|
||||
if (tok2->link() == NULL) {
|
||||
if (tok2->link() == nullptr) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "unmatched do in switch: " << tok2->linenr();
|
||||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
|
@ -982,7 +982,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
justbreak = false;
|
||||
} else if (Token::simpleMatch(tok2, "for (")) {
|
||||
tok2 = tok2->next()->link()->next();
|
||||
if (tok2->link() == NULL) {
|
||||
if (tok2->link() == nullptr) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "unmatched for in switch: " << tok2->linenr();
|
||||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
|
@ -1012,7 +1012,7 @@ void CheckOther::checkSwitchCaseFallThrough()
|
|||
if (tok2->next()->str() == "else") {
|
||||
tok2 = tok2->tokAt(2);
|
||||
ifnest.pop();
|
||||
if (tok2->link() == NULL) {
|
||||
if (tok2->link() == nullptr) {
|
||||
std::ostringstream errmsg;
|
||||
errmsg << "unmatched if in switch: " << tok2->linenr();
|
||||
reportError(_tokenizer->tokens(), Severity::debug, "debug", errmsg.str());
|
||||
|
@ -1530,7 +1530,7 @@ void CheckOther::invalidFunctionUsage()
|
|||
sprintfOverlappingDataError(tok2, tok2->str());
|
||||
break;
|
||||
}
|
||||
} while (NULL != (tok2 = tok2->nextArgument()));
|
||||
} while (nullptr != (tok2 = tok2->nextArgument()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2198,7 +2198,7 @@ void CheckOther::checkZeroDivision()
|
|||
// Value flow..
|
||||
const ValueFlow::Value *value = tok->astOperand2()->getValue(0LL);
|
||||
if (value) {
|
||||
if (value->condition == NULL)
|
||||
if (value->condition == nullptr)
|
||||
zerodivError(tok);
|
||||
else if (_settings->isEnabled("warning"))
|
||||
zerodivcondError(value->condition,tok);
|
||||
|
@ -2628,7 +2628,7 @@ void CheckOther::checkInvalidFree()
|
|||
// if it is later used to free memory
|
||||
else if (Token::Match(tok, "%var% (")) {
|
||||
const Token* tok2 = Token::findmatch(tok->next(), "%var%", tok->linkAt(1));
|
||||
while (tok2 != NULL) {
|
||||
while (tok2 != nullptr) {
|
||||
allocatedVariables.erase(tok2->varId());
|
||||
tok2 = Token::findmatch(tok2->next(), "%var%", tok->linkAt(1));
|
||||
}
|
||||
|
@ -2698,7 +2698,7 @@ void CheckOther::checkDoubleFree()
|
|||
else if (tok->str() == "}" && tok->link() && tok->link()->previous() &&
|
||||
tok->link()->linkAt(-1) &&
|
||||
Token::Match(tok->link()->linkAt(-1)->previous(), "while|for") &&
|
||||
Token::findmatch(tok->link()->linkAt(-1), "break|continue ;", tok) != NULL) {
|
||||
Token::findmatch(tok->link()->linkAt(-1), "break|continue ;", tok) != nullptr) {
|
||||
freedVariables.clear();
|
||||
closeDirVariables.clear();
|
||||
}
|
||||
|
@ -2855,7 +2855,7 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
|
|||
return;
|
||||
|
||||
const Token *tok = _tokenizer->tokens();
|
||||
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %str% , %str% ")) != NULL) {
|
||||
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %str% , %str% ")) != nullptr) {
|
||||
const std::string &str1 = tok->strAt(2);
|
||||
const std::string &str2 = tok->strAt(4);
|
||||
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
||||
|
@ -2863,7 +2863,7 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
|
|||
}
|
||||
|
||||
tok = _tokenizer->tokens();
|
||||
while (tok && (tok = Token::findmatch(tok, "QString :: compare ( %str% , %str% )")) != NULL) {
|
||||
while (tok && (tok = Token::findmatch(tok, "QString :: compare ( %str% , %str% )")) != nullptr) {
|
||||
const std::string &str1 = tok->strAt(4);
|
||||
const std::string &str2 = tok->strAt(6);
|
||||
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
||||
|
@ -2871,7 +2871,7 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
|
|||
}
|
||||
|
||||
tok = _tokenizer->tokens();
|
||||
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %var% , %var% ")) != NULL) {
|
||||
while (tok && (tok = Token::findmatch(tok, "strncmp|strcmp|stricmp|strcmpi|strcasecmp|wcscmp|wcsncmp ( %var% , %var% ")) != nullptr) {
|
||||
const std::string &str1 = tok->strAt(2);
|
||||
const std::string &str2 = tok->strAt(4);
|
||||
if (str1 == str2)
|
||||
|
@ -2880,7 +2880,7 @@ void CheckOther::checkAlwaysTrueOrFalseStringCompare()
|
|||
}
|
||||
|
||||
tok = _tokenizer->tokens();
|
||||
while (tok && (tok = Token::findmatch(tok, "!!+ %str% ==|!= %str% !!+")) != NULL) {
|
||||
while (tok && (tok = Token::findmatch(tok, "!!+ %str% ==|!= %str% !!+")) != nullptr) {
|
||||
const std::string &str1 = tok->strAt(1);
|
||||
const std::string &str2 = tok->strAt(3);
|
||||
alwaysTrueFalseStringCompareError(tok, str1, str2);
|
||||
|
@ -3318,7 +3318,7 @@ void CheckOther::oppositeInnerCondition()
|
|||
|
||||
if (scope->classDef->strAt(6) == "{") {
|
||||
|
||||
const char *oppositeCondition = NULL;
|
||||
const char *oppositeCondition = nullptr;
|
||||
|
||||
if (scope->classDef->strAt(3) == "==")
|
||||
oppositeCondition = "if ( %any% !=|<|>|<=|>= %any% )";
|
||||
|
@ -3388,13 +3388,13 @@ void CheckOther::checkVarFuncNullUB()
|
|||
++argnr;
|
||||
ftok = ftok->previous();
|
||||
}
|
||||
ftok = ftok ? ftok->previous() : NULL;
|
||||
ftok = ftok ? ftok->previous() : nullptr;
|
||||
if (ftok && ftok->isName()) {
|
||||
// If this is a variadic function then report error
|
||||
const Function *f = ftok->function();
|
||||
if (f && f->argCount() <= argnr) {
|
||||
const Token *tok2 = f->argDef;
|
||||
tok2 = tok2 ? tok2->link() : NULL; // goto ')'
|
||||
tok2 = tok2 ? tok2->link() : nullptr; // goto ')'
|
||||
if (Token::simpleMatch(tok2->tokAt(-3), ". . ."))
|
||||
varFuncNullUBError(tok);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ void CheckStl::iterators()
|
|||
if (container && tok2->varId() != container->declarationId()) {
|
||||
// skip error message if container is a set..
|
||||
const Variable *variableInfo = tok2->variable();
|
||||
const Token *decltok = variableInfo ? variableInfo->typeStartToken() : NULL;
|
||||
const Token *decltok = variableInfo ? variableInfo->typeStartToken() : nullptr;
|
||||
|
||||
if (Token::simpleMatch(decltok, "std :: set"))
|
||||
continue; // No warning
|
||||
|
@ -434,7 +434,7 @@ private:
|
|||
// check if there is a "it = ints.erase(it);" pattern. if so
|
||||
// the it is not invalidated.
|
||||
const Token *token = &tok;
|
||||
while (NULL != (token = token ? token->previous() : 0)) {
|
||||
while (nullptr != (token = token ? token->previous() : 0)) {
|
||||
if (Token::Match(token, "[;{}]"))
|
||||
break;
|
||||
else if (token->str() == "=")
|
||||
|
@ -506,7 +506,7 @@ void CheckStl::erase()
|
|||
if (Token::Match(tok2, "; %var% !=")) {
|
||||
// Get declaration token for var..
|
||||
const Variable *variableInfo = tok2->next()->variable();
|
||||
const Token *decltok = variableInfo ? variableInfo->typeEndToken() : NULL;
|
||||
const Token *decltok = variableInfo ? variableInfo->typeEndToken() : nullptr;
|
||||
|
||||
// Is variable an iterator?
|
||||
bool isIterator = false;
|
||||
|
|
|
@ -368,7 +368,7 @@ private:
|
|||
*/
|
||||
static void parserhs(const Token *tok2, std::list<ExecutionPath *> &checks) {
|
||||
// check variable usages in rhs/index
|
||||
while (NULL != (tok2 = tok2->next())) {
|
||||
while (nullptr != (tok2 = tok2->next())) {
|
||||
if (Token::Match(tok2, "[;)=]"))
|
||||
break;
|
||||
if (Token::Match(tok2, "%var% ("))
|
||||
|
@ -713,7 +713,7 @@ private:
|
|||
if (Token::Match(tok2->tokAt(-2), "[(,] *") || Token::Match(tok2->next(), ". %var%")) {
|
||||
// find function call..
|
||||
const Token *functionCall = tok2;
|
||||
while (NULL != (functionCall = functionCall ? functionCall->previous() : 0)) {
|
||||
while (nullptr != (functionCall = functionCall ? functionCall->previous() : 0)) {
|
||||
if (functionCall->str() == "(")
|
||||
break;
|
||||
if (functionCall->str() == ")")
|
||||
|
@ -1097,7 +1097,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
|
|||
}
|
||||
if (stdtype || i->isPointer()) {
|
||||
bool alloc = false;
|
||||
checkScopeForVariable(scope, tok, *i, NULL, NULL, &alloc, "");
|
||||
checkScopeForVariable(scope, tok, *i, nullptr, nullptr, &alloc, "");
|
||||
}
|
||||
if (Token::Match(i->typeStartToken(), "struct %type% *| %var% ;"))
|
||||
checkStruct(scope, tok, *i);
|
||||
|
@ -1115,7 +1115,7 @@ void CheckUninitVar::checkScope(const Scope* scope)
|
|||
checkStruct(scope, tok, *arg);
|
||||
else if (arg->typeStartToken()->isStandardType()) {
|
||||
bool alloc = false;
|
||||
checkScopeForVariable(scope, tok->next(), *arg, NULL, NULL, &alloc, "");
|
||||
checkScopeForVariable(scope, tok->next(), *arg, nullptr, nullptr, &alloc, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1156,7 +1156,7 @@ void CheckUninitVar::checkStruct(const Scope* scope, const Token *tok, const Var
|
|||
const Token *tok2 = tok;
|
||||
if (tok->str() == "}")
|
||||
tok2 = tok2->next();
|
||||
checkScopeForVariable(scope, tok2, structvar, NULL, NULL, &alloc, var.name());
|
||||
checkScopeForVariable(scope, tok2, structvar, nullptr, nullptr, &alloc, var.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1239,7 +1239,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
|
||||
// Unconditional inner scope..
|
||||
if (tok->str() == "{" && Token::Match(tok->previous(), "[;{}]")) {
|
||||
if (checkScopeForVariable(scope, tok->next(), var, possibleInit, NULL, alloc, membervar))
|
||||
if (checkScopeForVariable(scope, tok->next(), var, possibleInit, nullptr, alloc, membervar))
|
||||
return true;
|
||||
tok = tok->link();
|
||||
continue;
|
||||
|
@ -1330,7 +1330,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
|
||||
bool possibleInitElse(number_of_if > 0 || suppressErrors);
|
||||
bool noreturnElse = false;
|
||||
const bool initelse = !alwaysTrue && checkScopeForVariable(scope, tok->next(), var, &possibleInitElse, NULL, alloc, membervar);
|
||||
const bool initelse = !alwaysTrue && checkScopeForVariable(scope, tok->next(), var, &possibleInitElse, nullptr, alloc, membervar);
|
||||
|
||||
std::map<unsigned int, int> varValueElse;
|
||||
if (!alwaysTrue && !initelse && !noreturnElse) {
|
||||
|
@ -1479,7 +1479,7 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok,
|
|||
tok = tok->next();
|
||||
}
|
||||
|
||||
return bool(noreturn==NULL);
|
||||
return bool(noreturn==nullptr);
|
||||
}
|
||||
|
||||
// variable is seen..
|
||||
|
@ -1564,7 +1564,7 @@ bool CheckUninitVar::checkIfForWhileHead(const Token *startparentheses, const Va
|
|||
|
||||
bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const bool alloc, const std::string &membervar, const bool suppressErrors)
|
||||
{
|
||||
const Token *usetok = NULL;
|
||||
const Token *usetok = nullptr;
|
||||
|
||||
assert(tok->str() == "{");
|
||||
|
||||
|
@ -1643,7 +1643,7 @@ void CheckUninitVar::checkRhs(const Token *tok, const Variable &var, bool alloc,
|
|||
{
|
||||
bool rhs = false;
|
||||
unsigned int indent = 0;
|
||||
while (NULL != (tok = tok->next())) {
|
||||
while (nullptr != (tok = tok->next())) {
|
||||
if (tok->str() == "=")
|
||||
rhs = true;
|
||||
else if (rhs && tok->varId() == var.declarationId()) {
|
||||
|
|
|
@ -381,7 +381,7 @@ void Variables::leaveScope(bool insideLoop)
|
|||
for (std::set<unsigned int>::const_iterator readIter = currentVarReadInScope.begin();
|
||||
readIter != currentVarReadInScope.end();
|
||||
++readIter) {
|
||||
read(*readIter, NULL);
|
||||
read(*readIter, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1192,7 +1192,7 @@ void CheckUnusedVar::checkStructMemberUsage()
|
|||
if (!structname.empty()) {
|
||||
const std::string pattern1(structname + " %var% ;");
|
||||
const Token *tok2 = tok;
|
||||
while (NULL != (tok2 = Token::findmatch(tok2->next(), pattern1.c_str()))) {
|
||||
while (nullptr != (tok2 = Token::findmatch(tok2->next(), pattern1.c_str()))) {
|
||||
if (Token::simpleMatch(tok2->tokAt(3), (tok2->strAt(1) + " = {").c_str())) {
|
||||
structname.clear();
|
||||
break;
|
||||
|
|
|
@ -451,7 +451,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
|
|||
|
||||
const char *error = 0;
|
||||
int erroffset = 0;
|
||||
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,NULL);
|
||||
pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,nullptr);
|
||||
if (!re) {
|
||||
if (error) {
|
||||
ErrorLogger::ErrorMessage errmsg(std::list<ErrorLogger::ErrorMessage::FileLocation>(),
|
||||
|
@ -467,7 +467,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token
|
|||
|
||||
int pos = 0;
|
||||
int ovector[30];
|
||||
while (pos < (int)str.size() && 0 <= pcre_exec(re, NULL, str.c_str(), (int)str.size(), pos, 0, ovector, 30)) {
|
||||
while (pos < (int)str.size() && 0 <= pcre_exec(re, nullptr, str.c_str(), (int)str.size(), pos, 0, ovector, 30)) {
|
||||
unsigned int pos1 = (unsigned int)ovector[0];
|
||||
unsigned int pos2 = (unsigned int)ovector[1];
|
||||
|
||||
|
|
Loading…
Reference in New Issue