diff --git a/src/checkbufferoverrun.cpp b/src/checkbufferoverrun.cpp index 35e88bd0d..0def26a6c 100644 --- a/src/checkbufferoverrun.cpp +++ b/src/checkbufferoverrun.cpp @@ -267,9 +267,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, const char *varname[], con if (value <= size) condition_out_of_bounds = false;; - // Goto the end of the for loop.. - while (tok2 && tok2->str() != ")") - tok2 = tok2->next(); + // Goto the end paranthesis of the for-statement: "for (x; y; z)" .. + tok2 = tok->next()->link(); if (!tok2 || !tok2->tokAt(5)) break; diff --git a/src/checkmemoryleak.cpp b/src/checkmemoryleak.cpp index 31cc56c2f..f304cabf2 100644 --- a/src/checkmemoryleak.cpp +++ b/src/checkmemoryleak.cpp @@ -62,8 +62,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getAllocationType(const Token *tok2, // * var = strndup("hello", 3); if (tok2 && tok2->str() == "(") { - while (tok2 && tok2->str() != ")") - tok2 = tok2->next(); + tok2 = tok2->link(); tok2 = tok2 ? tok2->next() : NULL; } if (! tok2) @@ -143,8 +142,7 @@ CheckMemoryLeak::AllocType CheckMemoryLeak::getReallocationType(const Token *tok // * var = (char *)realloc(..; if (tok2 && tok2->str() == "(") { - while (tok2 && tok2->str() != ")") - tok2 = tok2->next(); + tok2 = tok2->link(); tok2 = tok2 ? tok2->next() : NULL; } if (! tok2) @@ -735,8 +733,7 @@ Token *CheckMemoryLeakInFunction::getcode(const Token *tok, std::liststr() != ")") - tok = tok->next(); + tok = tok->next()->link(); } else if (Token::simpleMatch(tok, std::string("if ( " + varnameStr + " == -1 )").c_str()) || Token::simpleMatch(tok, std::string("if ( " + varnameStr + " < 0 )").c_str())) @@ -2068,24 +2065,14 @@ void CheckMemoryLeakStructMember::check() else if (Token::Match(tok3, "if ( ! %var% . %varid% )", structmemberid)) { // Goto the ")" - while (tok3->str() != ")") - tok3 = tok3->next(); + tok3 = tok3->next()->link(); - // Skip block.. - unsigned int indentlevel = 0; - while (tok3) - { - if (tok3->str() == "{") - ++indentlevel; + // make sure we have ") {".. it should be + if (!Token::simpleMatch(tok3, ") {")) + break; - else if (tok3->str() == "}") - { - if (indentlevel <= 1) - break; - --indentlevel; - } - tok3 = tok3->next(); - } + // Goto the "}" + tok3 = tok3->next()->link(); } // Returning from function.. diff --git a/src/checkother.cpp b/src/checkother.cpp index b79ff952e..2f034a5ad 100644 --- a/src/checkother.cpp +++ b/src/checkother.cpp @@ -977,24 +977,17 @@ void CheckOther::nullPointer() // Locate the end of the while loop.. const Token *tok2 = tok->tokAt(4); - int indentlevel = 0; - while (tok2) + if (tok2->str() == "{") + tok2 = tok2->link(); + else { - if (tok2->str() == "{") - ++indentlevel; - else if (tok2->str() == "}") - { - if (indentlevel <= 1) - break; - --indentlevel; - } - else if (indentlevel == 0 && tok2->str() == ";") - break; - tok2 = tok2->next(); + while (tok2 && tok2->str() != ";") + tok2 = tok2->next(); } // Goto next token - tok2 = tok2 ? tok2->next() : 0; + if (tok2) + tok2 = tok2->next(); // Check if the variable is dereferenced.. while (tok2)