null pointers: fixed false positives (#49)
This commit is contained in:
parent
565ac2fca6
commit
06c8ff9d0d
|
@ -1090,11 +1090,15 @@ void CheckOther::nullPointer()
|
|||
{
|
||||
if (tok1->varId() == varid)
|
||||
{
|
||||
if (tok1->previous() && tok1->previous()->str() == "*")
|
||||
if (tok1->previous() && tok1->previous()->str() == "*" && !Token::simpleMatch(tok1->tokAt(-2), "*"))
|
||||
{
|
||||
nullPointerError(tok1);
|
||||
break;
|
||||
}
|
||||
else if (tok1->previous() && tok1->previous()->str() == "&")
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (tok1->next() && tok1->next()->str() == "=")
|
||||
{
|
||||
break;
|
||||
|
|
|
@ -523,6 +523,23 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference\n", errout.str());
|
||||
|
||||
// no error
|
||||
checkNullPointer("void foo()\n"
|
||||
"{\n"
|
||||
" int *p;\n"
|
||||
" f(&p);\n"
|
||||
" if (!p)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNullPointer("void foo()\n"
|
||||
"{\n"
|
||||
" int **p = f();\n"
|
||||
" if (!p)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNullPointer("void foo(int *p)\n"
|
||||
"{\n"
|
||||
" if (x)\n"
|
||||
|
|
Loading…
Reference in New Issue