null pointer: fixed false positive when condition checks if pointer is ok
This commit is contained in:
parent
feb065abc8
commit
7dbf22aa3f
|
@ -1129,6 +1129,22 @@ void CheckOther::nullPointerConditionalAssignment()
|
|||
tok3 = tok3->next()->link();
|
||||
if (!tok3)
|
||||
break;
|
||||
|
||||
// check if the condition contains the variable..
|
||||
for (const Token *tok4 = tok2->tokAt(2); tok4 && tok4 != tok3; tok4 = tok4->next())
|
||||
{
|
||||
if (tok4->varId() == varid)
|
||||
{
|
||||
// The condition contains the variable..
|
||||
// to avoid false positives I bail out..
|
||||
tok3 = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!tok3)
|
||||
break;
|
||||
|
||||
if (tok3->next()->str() == "{")
|
||||
{
|
||||
tok2 = tok3->next()->link();
|
||||
|
|
|
@ -910,6 +910,15 @@ private:
|
|||
" p->abcd();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
checkNullPointer("static void foo()\n"
|
||||
"{\n"
|
||||
" Foo *p = 0;\n"
|
||||
" if (!p)\n"
|
||||
" return;\n"
|
||||
" p->abcd();\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue