diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index 76a075e88..d5fa5b49a 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -79,7 +79,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra errmsg << " out of bounds."; } - const Token *condition = 0; + const Token *condition = nullptr; for (unsigned int i = 0; i < index.size(); ++i) { if (condition == nullptr) condition = index[i].condition; @@ -428,7 +428,7 @@ static bool for3(const Token * const tok, std::string &max_value, const bool maxMinFlipped) { - assert(tok != 0); + assert(tok != nullptr); if (Token::Match(tok, "%varid% = %num% + %varid% )", varid)) { if (!for_maxvalue(tok->tokAt(2), min_value, max_value)) return false; @@ -1498,7 +1498,7 @@ void CheckBufferOverrun::checkGlobalAndLocalVariable() std::string type; // varid : The variable id for the array - const Variable *var = 0; + const Variable *var = nullptr; // nextTok : number of tokens used in variable declaration - used to skip to next statement. int nextTok = 0; diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 9b16ea6b1..4fb84c261 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -917,8 +917,8 @@ void CheckClass::checkMemset() continue; - const Token *typeTok = 0; - const Scope *type = 0; + const Token *typeTok = nullptr; + const Scope *type = nullptr; if (Token::Match(arg3, "sizeof ( %type% ) )")) typeTok = arg3->tokAt(2); else if (Token::Match(arg3, "sizeof ( %type% :: %type% ) )")) @@ -1252,7 +1252,7 @@ bool CheckClass::hasAllocation(const Function *func, const Scope* scope) return true; // check for deallocating memory - const Token *var = 0; + const Token *var = nullptr; if (Token::Match(tok, "free ( %var%")) var = tok->tokAt(2); else if (Token::Match(tok, "delete [ ] %var%")) @@ -1395,7 +1395,7 @@ void CheckClass::virtualDestructor() // Find the destructor declaration for the base class. const Function *base_destructor = derivedFromScope->getDestructor(); - const Token *base = 0; + const Token *base = nullptr; if (base_destructor) base = base_destructor->token; diff --git a/lib/checkexceptionsafety.cpp b/lib/checkexceptionsafety.cpp index 6da9e687d..321fbb4e4 100644 --- a/lib/checkexceptionsafety.cpp +++ b/lib/checkexceptionsafety.cpp @@ -98,7 +98,7 @@ void CheckExceptionSafety::deallocThrow() const unsigned int varid(tok->varId()); // Token where throw occurs - const Token *ThrowToken = 0; + const Token *ThrowToken = nullptr; // is there a throw after the deallocation? const Token* const end2 = tok->scope()->classEnd; diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 9d6638e77..146a58886 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -318,7 +318,7 @@ void CheckIO::invalidScanf() for (std::size_t j = 0; j < functions; ++j) { const Scope * scope = symbolDatabase->functionScopes[j]; for (const Token *tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { - const Token *formatToken = 0; + const Token *formatToken = nullptr; if (Token::Match(tok, "scanf|vscanf ( %str% ,")) formatToken = tok->tokAt(2); else if (Token::Match(tok, "sscanf|vsscanf|fscanf|vfscanf (")) { @@ -424,7 +424,7 @@ static bool findFormat(unsigned int arg, const Token *firstArg, argTok->variable()->dimensionKnown(0) && argTok->variable()->dimension(0) != 0)))) { *formatArgTok = argTok->nextArgument(); - *formatStringTok = 0; + *formatStringTok = nullptr; if (argTok->variable()) { const Token *varTok = argTok->variable()->nameToken(); if (Token::Match(varTok, "%var% ; %var% = %str% ;") && @@ -1330,7 +1330,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * tok, const Settings *settings) tok = tok->tokAt(2); if (!tok || !(tok->type() == Token::eVariable || tok->type() == Token::eFunction)) return; - const Token *varTok = 0; + const Token *varTok = nullptr; const Token *tok1 = tok->next(); for (; tok1; tok1 = tok1->next()) { if (tok1->str() == "," || tok1->str() == ")") { diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 36ff92333..3eda73a0f 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -629,7 +629,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::listfunctionScope->classStart->next(), callstack, 0, alloctype, dealloctype, false, 1); simplifycode(ftok); - const char *ret = 0; + const char *ret = nullptr; if (Token::simpleMatch(ftok, "; alloc ; }")) ret = "alloc"; else if (Token::simpleMatch(ftok, "; dealloc ; }")) @@ -688,7 +688,7 @@ const char * CheckMemoryLeakInFunction::call_func(const Token *tok, std::liststr() == ";") func_ = func_->next(); - const char *ret = 0; + const char *ret = nullptr; /** @todo handle "goto" */ if (Token::findsimplematch(func_, "dealloc")) ret = "dealloc"; @@ -782,7 +782,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::listnext(); tok2; tok2 = tok2->next()) { diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 7de265021..1f5a84d50 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -629,8 +629,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef() continue; // vartok : token for the variable - const Token *vartok = 0; - const Token *checkConditionStart = 0; + const Token *vartok = nullptr; + const Token *checkConditionStart = nullptr; if (Token::Match(tok, "( ! %var% )|&&")) { vartok = tok->tokAt(2); checkConditionStart = vartok->next(); @@ -892,7 +892,7 @@ void CheckNullPointer::nullConstantDereference() } } - const Variable *ovar = 0; + const Variable *ovar = nullptr; if (Token::Match(tok, "0 ==|!= %var% !!.")) ovar = tok->tokAt(2)->variable(); else if (Token::Match(tok, "%var% ==|!= 0")) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index e22f0e72b..addf83d7f 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -514,7 +514,7 @@ void CheckOther::invalidPointerCast() continue; // Find casted variable - const Variable *var = 0; + const Variable *var = nullptr; bool allocation = false; bool ref = false; if (Token::Match(nextTok, "new %type%")) diff --git a/lib/checksizeof.cpp b/lib/checksizeof.cpp index a2ac2f761..c50014cc5 100644 --- a/lib/checksizeof.cpp +++ b/lib/checksizeof.cpp @@ -113,7 +113,7 @@ void CheckSizeof::checkSizeofForPointerSize() for (const Token* tok = scope->classStart; tok != scope->classEnd; tok = tok->next()) { const Token *tokVar; const Token *variable; - const Token *variable2 = 0; + const Token *variable2 = nullptr; // Find any function that may use sizeof on a pointer // Once leaving those tests, it is mandatory to have: diff --git a/lib/checkstl.cpp b/lib/checkstl.cpp index 7aec06541..e96799bdd 100644 --- a/lib/checkstl.cpp +++ b/lib/checkstl.cpp @@ -655,7 +655,7 @@ void CheckStl::pushback() if (varId == 0) continue; - const Token *pushbackTok = 0; + const Token *pushbackTok = nullptr; // Count { and } for tok3 const Token *tok3 = tok2->tokAt(20); @@ -1077,7 +1077,7 @@ void CheckStl::missingComparison() break; } - const Token *incrementToken = 0; + const Token *incrementToken = nullptr; // Parse loop.. for (const Token *tok3 = i->classStart; tok3 != i->classEnd; tok3 = tok3->next()) { diff --git a/lib/checkunusedfunctions.cpp b/lib/checkunusedfunctions.cpp index a846a63ca..b678d4fd1 100644 --- a/lib/checkunusedfunctions.cpp +++ b/lib/checkunusedfunctions.cpp @@ -51,7 +51,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi if (tok->previous() && tok->previous()->str() == ">") continue; - const Token *funcname = 0; + const Token *funcname = nullptr; if (Token::Match(tok, "%type% %var% (")) funcname = tok->next(); @@ -188,7 +188,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi } - const Token *funcname = 0; + const Token *funcname = nullptr; if (Token::Match(tok->next(), "%var% (")) { funcname = tok->next(); diff --git a/lib/checkunusedvar.cpp b/lib/checkunusedvar.cpp index 89ab17db6..81a26bcbb 100644 --- a/lib/checkunusedvar.cpp +++ b/lib/checkunusedvar.cpp @@ -40,7 +40,7 @@ public: /** Store information about variable usage */ class VariableUsage { public: - VariableUsage(const Variable *var = 0, + VariableUsage(const Variable *var = nullptr, VariableType type = standard, bool read = false, bool write = false, diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 389064426..5c8619574 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -449,7 +449,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const Tokenizer &token if (rule.pattern.empty() || rule.id.empty() || rule.severity.empty() || rule.tokenlist != tokenlist) continue; - const char *error = 0; + const char *error = nullptr; int erroffset = 0; pcre *re = pcre_compile(rule.pattern.c_str(),0,&error,&erroffset,nullptr); if (!re) { diff --git a/lib/preprocessor.h b/lib/preprocessor.h index 84cdbe8c9..cd5e021ae 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -54,7 +54,7 @@ public: /** character that is inserted in expanded macros */ static char macroChar; - Preprocessor(Settings *settings = 0, ErrorLogger *errorLogger = 0); + Preprocessor(Settings *settings = nullptr, ErrorLogger *errorLogger = nullptr); static bool missingIncludeFlag; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 650649ce0..5fa9481d7 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -310,8 +310,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti // check if in class or structure else if (scope->type == Scope::eClass || scope->type == Scope::eStruct) { - const Token *funcStart = 0; - const Token *argStart = 0; + const Token *funcStart = nullptr; + const Token *argStart = nullptr; // What section are we in.. if (tok->str() == "private:") @@ -558,8 +558,8 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti scope->definedType->friendList.push_back(friendInfo); } } else if (scope->type == Scope::eNamespace || scope->type == Scope::eGlobal) { - const Token *funcStart = 0; - const Token *argStart = 0; + const Token *funcStart = nullptr; + const Token *argStart = nullptr; // function? if (isFunction(tok, scope, &funcStart, &argStart)) { @@ -2723,7 +2723,7 @@ bool SymbolDatabase::isCPP() const const Scope *SymbolDatabase::findScope(const Token *tok, const Scope *startScope) const { - const Scope *scope = 0; + const Scope *scope = nullptr; // absolute path if (tok->str() == "::") { tok = tok->next(); diff --git a/lib/token.cpp b/lib/token.cpp index db48caf8b..4881ef9b5 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -846,7 +846,7 @@ Token* Token::nextArgument() const const Token * Token::findClosingBracket() const { - const Token *closing = 0; + const Token *closing = nullptr; if (_str == "<") { unsigned int depth = 0; diff --git a/lib/token.h b/lib/token.h index e4b9e1ceb..f3eee4df0 100644 --- a/lib/token.h +++ b/lib/token.h @@ -382,7 +382,7 @@ public: * @param title Title for the printout or use default parameter or 0 * for no title. */ - void printOut(const char *title = 0) const; + void printOut(const char *title = nullptr) const; /** * For debugging purposes, prints token and all tokens @@ -591,7 +591,7 @@ public: } const ValueFlow::Value * getMaxValue(bool condition) const { - const ValueFlow::Value *ret = 0; + const ValueFlow::Value *ret = nullptr; std::list::const_iterator it; for (it = values.begin(); it != values.end(); ++it) { if ((!ret || it->intvalue > ret->intvalue) && diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5f24b9cc0..1b6c51ed5 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -603,19 +603,19 @@ void Tokenizer::simplifyTypedef() Token *typeName; std::list pointers; - Token *typeStart = 0; - Token *typeEnd = 0; - Token *argStart = 0; - Token *argEnd = 0; - Token *arrayStart = 0; - Token *arrayEnd = 0; - Token *specStart = 0; - Token *specEnd = 0; + Token *typeStart = nullptr; + Token *typeEnd = nullptr; + Token *argStart = nullptr; + Token *argEnd = nullptr; + Token *arrayStart = nullptr; + Token *arrayEnd = nullptr; + Token *specStart = nullptr; + Token *specEnd = nullptr; Token *typeDef = tok; - Token *argFuncRetStart = 0; - Token *argFuncRetEnd = 0; - Token *funcStart = 0; - Token *funcEnd = 0; + Token *argFuncRetStart = nullptr; + Token *argFuncRetEnd = nullptr; + Token *funcStart = nullptr; + Token *funcEnd = nullptr; Token *tokOffset = tok->next(); bool function = false; bool functionPtr = false; @@ -626,8 +626,8 @@ void Tokenizer::simplifyTypedef() bool refToArray = false; bool ptrMember = false; bool typeOf = false; - Token *namespaceStart = 0; - Token *namespaceEnd = 0; + Token *namespaceStart = nullptr; + Token *namespaceEnd = nullptr; // check for invalid input if (!tok->next()) { @@ -4440,7 +4440,7 @@ void Tokenizer::simplifyConditionOperator() else tok->deleteNext(8); - Token *starttok = 0; + Token *starttok = nullptr; std::string str; if (isReturn) @@ -7347,9 +7347,9 @@ void Tokenizer::simplifyEnum() (!temp->isName() || !Token::Match(temp->next(), "[{:;]"))) continue; Token *start = tok; - Token *enumType = 0; - Token *typeTokenStart = 0; - Token *typeTokenEnd = 0; + Token *enumType = nullptr; + Token *typeTokenStart = nullptr; + Token *typeTokenEnd = nullptr; // check for C++0x enum class if (Token::Match(tok->next(), "class|struct")) @@ -7965,7 +7965,7 @@ void Tokenizer::eraseDeadCode(Token *begin, const Token *end) std::vector switchindents; bool checklabel = false; Token *tok = begin; - Token *tokcheck = 0; + Token *tokcheck = nullptr; while (tok->next() && tok->next() != end) { if (tok->next()->str() == "(") { ++roundbraces; @@ -8639,11 +8639,11 @@ void Tokenizer::removeExceptionSpecifications() bool Tokenizer::validate() const { std::stack linktok; - const Token *lastTok = 0; + const Token *lastTok = nullptr; for (const Token *tok = tokens(); tok; tok = tok->next()) { lastTok = tok; if (Token::Match(tok, "[{([]") || (tok->str() == "<" && tok->link())) { - if (tok->link() == 0) { + if (tok->link() == nullptr) { cppcheckError(tok); return false; } @@ -8652,7 +8652,7 @@ bool Tokenizer::validate() const } else if (Token::Match(tok, "[})]]") || (tok->str() == ">" && tok->link())) { - if (tok->link() == 0) { + if (tok->link() == nullptr) { cppcheckError(tok); return false; } @@ -8675,7 +8675,7 @@ bool Tokenizer::validate() const linktok.pop(); } - else if (tok->link() != 0) { + else if (tok->link() != nullptr) { cppcheckError(tok); return false; } @@ -8867,7 +8867,7 @@ void Tokenizer::simplifyErrNoInWhile() if (tok->str() != "errno") continue; - Token *endpar = 0; + Token *endpar = nullptr; if (Token::Match(tok->previous(), "&& errno == EINTR ) { ;| }")) endpar = tok->tokAt(3); else if (Token::Match(tok->tokAt(-2), "&& ( errno == EINTR ) ) { ;| }")) @@ -9018,7 +9018,7 @@ void Tokenizer::simplifyStructDecl() } if (!Token::simpleMatch(tok2, "} ;")) continue; - Token *vartok = 0; + Token *vartok = nullptr; tok2 = tok1->tokAt(2); while (Token::Match(tok2, "%type% %var% ;")) { if (!vartok) { @@ -9295,7 +9295,7 @@ void Tokenizer::simplifyBitfields() goback = false; tok = tok->previous(); } - Token *last = 0; + Token *last = nullptr; if (Token::Match(tok, ";|{|}|public:|protected:|private: const| %type% %var% :") && !Token::Match(tok->next(), "case|public|protected|private|class|struct") && diff --git a/lib/tokenize.h b/lib/tokenize.h index a89b74264..a3b1602b6 100644 --- a/lib/tokenize.h +++ b/lib/tokenize.h @@ -63,7 +63,7 @@ public: * \param unknown set to true if it's unknown if the scope is noreturn * \return true if scope ends with a function call that might be 'noreturn' */ - bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = 0) const; + bool IsScopeNoReturn(const Token *endScopeToken, bool *unknown = nullptr) const; /** * Tokenize code diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 4bbbea2d4..73f2d5bde 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -698,7 +698,7 @@ static Token * createAstAtToken(Token *tok) { if (Token::simpleMatch(tok,"for (")) { Token *tok2 = tok->tokAt(2); - Token *init1 = 0; + Token *init1 = nullptr; const Token * const endPar = tok->next()->link(); while (tok2 && tok2 != endPar && tok2->str() != ";") { if (tok2->str() == "<" && tok2->link()) { diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b884faf45..68330ec1f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -608,7 +608,7 @@ static void valueFlowForLoop(TokenList *tokenlist, ErrorLogger *errorLogger, con if (vartok->varId() == 0U) continue; tok = vartok->tokAt(4); - const Token *num2tok = 0; + const Token *num2tok = nullptr; if (Token::Match(tok, "%varid% <|<=|!=", vartok->varId())) { tok = tok->next(); num2tok = tok->astOperand2(); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index f26bbd94c..c75e1e731 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -836,7 +836,7 @@ private: void hasSubClassConstructor() { GET_SYMBOL_DB("class Foo { class Sub; }; class Foo::Sub { Sub() {} };"); - ASSERT(db != 0); + ASSERT(db != nullptr); if (db) { bool seen_something = false; @@ -930,11 +930,11 @@ private: ASSERT(db && db->scopeList.size() == 4); if (db) { const Scope* foo = db->findScopeByName("Foo"); - ASSERT(foo != 0); + ASSERT(foo != nullptr); const Scope* bar1 = db->findScopeByName("Bar1"); - ASSERT(bar1 != 0); + ASSERT(bar1 != nullptr); const Scope* bar2 = db->findScopeByName("Bar2"); - ASSERT(bar2 != 0); + ASSERT(bar2 != nullptr); if (foo && bar1 && bar2) { ASSERT(bar1->definedType->friendList.size() == 1 && bar1->definedType->friendList.front().name == "Foo" && bar1->definedType->friendList.front().type == foo->definedType); @@ -1159,7 +1159,7 @@ private: } } - ASSERT(scope != 0); + ASSERT(scope != nullptr); if (!scope) return; @@ -1193,7 +1193,7 @@ private: } } - ASSERT(scope != 0); + ASSERT(scope != nullptr); if (!scope) return; @@ -1836,14 +1836,14 @@ private: ASSERT_EQUALS("", errout.str()); if (db) { const Scope * bar = db->findScopeByName("bar"); - ASSERT(bar != 0); + ASSERT(bar != nullptr); if (bar) { unsigned int linenrs[] = { 2, 1 }; unsigned int index = 0; for (const Token * tok = bar->classStart->next(); tok != bar->classEnd; tok = tok->next()) { if (Token::Match(tok, "%var% (") && !tok->varId() && Token::simpleMatch(tok->linkAt(1), ") ;")) { const Function * function = db->findFunction(tok); - ASSERT(function != 0); + ASSERT(function != nullptr); if (function) { std::stringstream expected; expected << "Function call on line " << tok->linenr() << " calls function on line " << linenrs[index] << std::endl;