null pointers: fixed a false positive

This commit is contained in:
Daniel Marjamäki 2009-08-01 11:30:37 +02:00
parent f406babc32
commit e6713e9774
2 changed files with 13 additions and 0 deletions

View File

@ -1042,6 +1042,9 @@ void CheckOther::nullPointer()
if (varid == 0)
continue;
if (Token::Match(tok2->tokAt(-2), "%varid% ?", varid))
continue;
// Check usage of dereferenced variable in the loop..
unsigned int indentlevel3 = 0;
for (const Token *tok3 = tok1->next()->link(); tok3; tok3 = tok3->next())

View File

@ -446,6 +446,16 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference\n", errout.str());
checkNullPointer("void foo()\n"
"{\n"
" for (const Token *tok = tokens; tok; tok = tok ? tok->next() : NULL)\n"
" {\n"
" while (tok && tok->str() != \";\")\n"
" tok = tok->next();\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void nullpointer2()