From 767413adad8531369f70be403b0a0558ae5ac33b Mon Sep 17 00:00:00 2001 From: Edoardo Prezioso Date: Thu, 1 Dec 2011 10:48:14 +0100 Subject: [PATCH] 1)internal check found a 'findmatch' with simple string argument; 2)Style: uniform 'while (...)' when inside it there's an assignment; 3)Replace '0' with 'NULL' where there's comparison with a pointer. --- lib/checkautovariables.cpp | 2 +- lib/checkclass.cpp | 2 +- lib/checkmemoryleak.cpp | 10 +++++----- lib/checknullpointer.cpp | 4 +++- lib/checkother.cpp | 2 +- lib/checkuninitvar.cpp | 2 +- lib/preprocessor.cpp | 2 +- lib/tokenize.cpp | 12 ++++++------ 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 732c59213..4b17a5fc5 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -251,7 +251,7 @@ bool CheckAutoVariables::returnTemporary(const Token *tok) const { if (!Token::Match(tok, "return %var% (")) return false; - return bool(0 != Token::findmatch(_tokenizer->tokens(), ("std :: string " + tok->next()->str() + " (").c_str())); + return bool(NULL != Token::findmatch(_tokenizer->tokens(), ("std :: string " + tok->next()->str() + " (").c_str())); } //--------------------------------------------------------------------------- diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index d9421843d..b57818a06 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -1345,7 +1345,7 @@ static unsigned int countParameters(const Token *tok) return 0; unsigned int numpar = 1; - while ((tok = tok->nextArgument())) + while (NULL != (tok = tok->nextArgument())) numpar++; return numpar; diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index 84f3e6aa2..8dd8e2ca1 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -445,7 +445,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::functionReturnType(const Token *tok, // Check if return pointer is allocated.. AllocType allocType = No; - while (0 != (tok = tok->next())) { + while (NULL != (tok = tok->next())) { if (Token::Match(tok, "%varid% =", varid)) { allocType = getAllocationType(tok->tokAt(2), varid, callstack); } @@ -516,7 +516,7 @@ const char *CheckMemoryLeak::functionArgAlloc(const Token *tok, unsigned int tar // Check if pointer is allocated. unsigned int indentlevel = 0; int realloc = 0; - while (0 != (tok = tok->next())) { + while (NULL != (tok = tok->next())) { if (tok->str() == "{") ++indentlevel; else if (tok->str() == "}") { @@ -608,7 +608,7 @@ static unsigned int countParameters(const Token *tok) return 0; unsigned int numpar = 1; - while ((tok = tok->nextArgument())) + while (NULL != (tok = tok->nextArgument())) numpar++; return numpar; @@ -1670,7 +1670,7 @@ void CheckMemoryLeakInFunction::simplifycode(Token *tok) // Delete "if { dealloc|assign|use ; return ; }" else if (Token::Match(tok2, "[;{}] if { dealloc|assign|use ; return ; }") && - !Token::findmatch(tok, "if alloc ;")) { + !Token::findsimplematch(tok, "if alloc ;")) { Token::eraseTokens(tok2, tok2->tokAt(8)); if (Token::simpleMatch(tok2->next(), "else")) tok2->deleteNext(); @@ -2356,7 +2356,7 @@ void CheckMemoryLeakInFunction::parseFunctionScope(const Token *tok, const Token const Token *vartok = tok->tokAt(2); checkScope(tok->next(), vartok->str(), vartok->varId(), classmember, sz); } - } while (0 != (tok = tok->next())); + } while (NULL != (tok = tok->next())); } void CheckMemoryLeakInFunction::check() diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 83880a80f..e122cc670 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -308,8 +308,10 @@ void CheckNullPointer::nullPointerAfterLoop() // Is this checking inconclusive? bool inconclusive = false; + if (!tok2) + continue; // Check if the variable is dereferenced after the while loop - while (0 != (tok2 = tok2 ? tok2->next() : 0)) { + while (NULL != (tok2 = tok2->next())) { // inner and outer scopes if (tok2->str() == "{" || tok2->str() == "}") { // Not inconclusive: bail out diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 3b044097a..b848dfd2d 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1143,7 +1143,7 @@ void CheckOther::invalidFunctionUsage() sprintfOverlappingDataError(tok2->next(), tok2->next()->str()); break; } - } while ((tok2 = tok2->nextArgument()) != NULL); + } while (NULL != (tok2 = tok2->nextArgument())); } } diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 6b8bf18d9..3ef95d961 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -668,7 +668,7 @@ private: if (Token::Match(tok2->tokAt(-2), "[(,] *") || Token::Match(tok2->next(), ". %var%")) { // find function call.. const Token *functionCall = tok2; - while (0 != (functionCall = functionCall ? functionCall->previous() : 0)) { + while (NULL != (functionCall = functionCall ? functionCall->previous() : 0)) { if (functionCall->str() == "(") break; if (functionCall->str() == ")") diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 40bb1b753..47e171b8f 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -2334,7 +2334,7 @@ public: tok = tok->next(); if (tok) { bool optcomma = false; - while ((tok = tok->next()) != NULL) { + while (NULL != (tok = tok->next())) { std::string str = tok->str(); if (str == "##") continue; diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 4ed5c0869..01e537447 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -2554,7 +2554,7 @@ void Tokenizer::labels() // Simplify labels in the executable scope.. unsigned int indentlevel = 0; unsigned int indentroundbraces = 0; - while (0 != (tok = tok->next())) { + while (NULL != (tok = tok->next())) { if (tok->str() == "{") ++indentlevel; else if (tok->str() == "}") { @@ -2571,7 +2571,7 @@ void Tokenizer::labels() --indentroundbraces; } if (!indentroundbraces && tok->str() == "case") { - while (0 != (tok = tok->next())) { + while (NULL != (tok = tok->next())) { if (Token::Match(tok->previous(), "%any% :")) break; } @@ -2737,7 +2737,7 @@ std::set Tokenizer::simplifyTemplatesExpandSpecialized() tok->deleteThis(); // Use this special template in the code.. - while (0 != (tok2 = const_cast(Token::findmatch(tok2, pattern.c_str())))) { + while (NULL != (tok2 = const_cast(Token::findmatch(tok2, pattern.c_str())))) { Token::eraseTokens(tok2, Token::findsimplematch(tok2, "(")); tok2->str(name); } @@ -4797,7 +4797,7 @@ bool Tokenizer::simplifyIfAddBraces() // * if (cond) for (;;) break; // * if (cond1) if (cond2) { } // * if (cond1) if (cond2) ; else ; - while ((tempToken = tempToken->next()) != NULL) { + while (NULL != (tempToken = tempToken->next())) { if (tempToken->str() == "{") { if (Token::simpleMatch(tempToken->previous(),"else {")) { if (innerIf) @@ -5779,7 +5779,7 @@ void Tokenizer::simplifyVarDecl(bool only_k_r_fpar) insertTokens(tok2, type0, typelen); std::stack link1; std::stack link2; - while (((typelen--) > 0) && (0 != (tok2 = tok2->next()))) { + while (((typelen--) > 0) && (NULL != (tok2 = tok2->next()))) { if (tok2->str() == "(") link1.push(tok2); else if (tok2->str() == ")" && !link1.empty()) { @@ -6357,7 +6357,7 @@ bool Tokenizer::simplifyLogicalOperators() continue; const Token *tok2 = tok; - while (0 != (tok2 = tok2->previous())) { + while (NULL != (tok2 = tok2->previous())) { if (tok2->str() == ")") tok2 = tok2->link(); else if (Token::Match(tok2, "(|;|{|}"))