Fixed #2789 (null pointer: problems not detected when pointer is assigned and checked if it's null in a if statement)
This commit is contained in:
parent
8e888a0dfb
commit
a6c7ae8d51
|
@ -636,6 +636,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
|
|||
vartok = tok->tokAt(3);
|
||||
else if (Token::Match(tok, "if|while ( %var% )|&&"))
|
||||
vartok = tok->tokAt(2);
|
||||
else if (Token::Match(tok, "if ( ! ( %var% ="))
|
||||
vartok = tok->tokAt(4);
|
||||
else
|
||||
continue;
|
||||
|
||||
|
|
|
@ -1177,6 +1177,14 @@ private:
|
|||
" return fred->a;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:3]: (error) Possible null pointer dereference: fred - otherwise it is redundant to check if fred is null at line 2\n", errout.str());
|
||||
|
||||
// #2789 - assign and check pointer
|
||||
check("void f() {\n"
|
||||
" char *p;\n"
|
||||
" if (!(p=x())) { }\n"
|
||||
" *p = 0;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p - otherwise it is redundant to check if p is null at line 3\n", errout.str());
|
||||
}
|
||||
|
||||
// Test CheckNullPointer::nullConstantDereference
|
||||
|
|
Loading…
Reference in New Issue