Null pointer: reduce false negatives in pointerDerefAndCheck
This commit is contained in:
parent
825dce5c4e
commit
08f27564fa
|
@ -513,7 +513,7 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
||||||
// TODO: false negatives.
|
// TODO: false negatives.
|
||||||
// - logical operators
|
// - logical operators
|
||||||
// - while
|
// - while
|
||||||
if (tok->str() == "if" && Token::Match(tok->previous(), "; if ( !| %var% )"))
|
if (tok->str() == "if" && Token::Match(tok->previous(), "; if ( !| %var% )|%oror%|&&"))
|
||||||
{
|
{
|
||||||
const Token * vartok = tok->tokAt(2);
|
const Token * vartok = tok->tokAt(2);
|
||||||
if (vartok->str() == "!")
|
if (vartok->str() == "!")
|
||||||
|
|
|
@ -406,6 +406,13 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
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());
|
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());
|
||||||
|
|
||||||
|
check("void foo(int *p)\n"
|
||||||
|
"{\n"
|
||||||
|
" *p = 0;\n"
|
||||||
|
" if (p || q) { }\n"
|
||||||
|
"}\n");
|
||||||
|
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());
|
||||||
|
|
||||||
check("void foo(int *p)\n"
|
check("void foo(int *p)\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
" bar(*p);\n"
|
" bar(*p);\n"
|
||||||
|
|
Loading…
Reference in New Issue