null pointers: fixed TODO assertion - dereference pointer in function call and then checking that it is not NULL

This commit is contained in:
Daniel Marjamäki 2010-08-05 08:19:36 +02:00
parent 6f228033d2
commit 65f7bcbfa5
2 changed files with 10 additions and 5 deletions

View File

@ -2454,17 +2454,22 @@ void CheckOther::nullPointerByDeRefAndChec()
{
if (Token::Match(tok1->tokAt(-2), "[=;{}] *"))
{
nullPointerError(tok1, varname);
nullPointerError(tok1, varname, tok->linenr());
break;
}
else if (tok1->previous() && tok1->previous()->str() == "&")
else if (Token::simpleMatch(tok1->previous(), "&"))
{
break;
}
else if (tok1->next() && tok1->next()->str() == "=")
else if (Token::simpleMatch(tok1->next(), "="))
{
break;
}
// dereference in function call
else if (Token::Match(tok1->tokAt(-2), "[(,] *"))
{
nullPointerError(tok1, varname, tok->linenr());
}
}
else if (tok1->str() == "{" ||

View File

@ -911,7 +911,7 @@ private:
" if (!p)\n"
" ;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 4\n", errout.str());
checkNullPointer("void foo(int *p)\n"
"{\n"
@ -919,7 +919,7 @@ private:
" if (!p)\n"
" ;\n"
"}\n");
TODO_ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p\n", errout.str());
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 4\n", errout.str());
// no error
checkNullPointer("void foo()\n"