null pointers: fixed TODO assertion - dereference pointer in function call and then checking that it is not NULL
This commit is contained in:
parent
6f228033d2
commit
65f7bcbfa5
|
@ -2454,17 +2454,22 @@ void CheckOther::nullPointerByDeRefAndChec()
|
||||||
{
|
{
|
||||||
if (Token::Match(tok1->tokAt(-2), "[=;{}] *"))
|
if (Token::Match(tok1->tokAt(-2), "[=;{}] *"))
|
||||||
{
|
{
|
||||||
nullPointerError(tok1, varname);
|
nullPointerError(tok1, varname, tok->linenr());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (tok1->previous() && tok1->previous()->str() == "&")
|
else if (Token::simpleMatch(tok1->previous(), "&"))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (tok1->next() && tok1->next()->str() == "=")
|
else if (Token::simpleMatch(tok1->next(), "="))
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// dereference in function call
|
||||||
|
else if (Token::Match(tok1->tokAt(-2), "[(,] *"))
|
||||||
|
{
|
||||||
|
nullPointerError(tok1, varname, tok->linenr());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (tok1->str() == "{" ||
|
else if (tok1->str() == "{" ||
|
||||||
|
|
|
@ -911,7 +911,7 @@ private:
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\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"
|
checkNullPointer("void foo(int *p)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -919,7 +919,7 @@ private:
|
||||||
" if (!p)\n"
|
" if (!p)\n"
|
||||||
" ;\n"
|
" ;\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
|
// no error
|
||||||
checkNullPointer("void foo()\n"
|
checkNullPointer("void foo()\n"
|
||||||
|
|
Loading…
Reference in New Issue