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.
This commit is contained in:
parent
c5695503b3
commit
767413adad
|
@ -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()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1143,7 +1143,7 @@ void CheckOther::invalidFunctionUsage()
|
|||
sprintfOverlappingDataError(tok2->next(), tok2->next()->str());
|
||||
break;
|
||||
}
|
||||
} while ((tok2 = tok2->nextArgument()) != NULL);
|
||||
} while (NULL != (tok2 = tok2->nextArgument()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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() == ")")
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<std::string> Tokenizer::simplifyTemplatesExpandSpecialized()
|
|||
tok->deleteThis();
|
||||
|
||||
// Use this special template in the code..
|
||||
while (0 != (tok2 = const_cast<Token *>(Token::findmatch(tok2, pattern.c_str())))) {
|
||||
while (NULL != (tok2 = const_cast<Token *>(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<Token *> link1;
|
||||
std::stack<Token *> 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, "(|;|{|}"))
|
||||
|
|
Loading…
Reference in New Issue