diff --git a/lib/checknullpointer.cpp b/lib/checknullpointer.cpp index 5a60e99ae..7439591d6 100644 --- a/lib/checknullpointer.cpp +++ b/lib/checknullpointer.cpp @@ -201,7 +201,7 @@ void CheckNullPointer::nullPointerAfterLoop() // TODO: Aren't there false negatives. Shouldn't other loops be handled such as: // - while ( ! %var% ) // - while ( %var% && .. ) - if (! Token::Match(tok, "while ( %var% )")) + if (! Token::Match(tok, "while ( %var% )|&&")) continue; // Get variable id for the loop variable @@ -217,7 +217,7 @@ void CheckNullPointer::nullPointerAfterLoop() const std::string varname(tok->strAt(2)); // Locate the end of the while loop body.. - const Token *tok2 = tok->tokAt(4)->link(); + const Token *tok2 = tok->next()->link()->next()->link(); // Check if the variable is dereferenced after the while loop while (0 != (tok2 = tok2 ? tok2->next() : 0)) diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 3407604b7..7438480d8 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -88,12 +88,12 @@ private: check("void foo(const Token *tok)\n" "{\n" " while (tok && tok->str() == \"=\")\n" - " tok = tok->tokAt(-2);\n" + " tok = tok->next();\n" "\n" " if (tok->str() != \";\")\n" " ;\n" "}\n"); - TODO_ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check if tok is null at line 3\n", "", errout.str()); + ASSERT_EQUALS("[test.cpp:6]: (error) Possible null pointer dereference: tok - otherwise it is redundant to check if tok is null at line 3\n", errout.str()); check("void foo()\n" "{\n"