Null pointers: Fixed false negative when struct is dereferenced in condition
This commit is contained in:
parent
9b9a0de777
commit
0c2f2e1c38
|
@ -379,9 +379,11 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
|
||||||
}
|
}
|
||||||
|
|
||||||
// dereference in condition
|
// dereference in condition
|
||||||
else if (Token::Match(tok1, "if ( %var% ."))
|
else if (Token::Match(tok1, "if ( !| %var% ."))
|
||||||
{
|
{
|
||||||
tok1 = tok1->tokAt(2);
|
tok1 = tok1->tokAt(2);
|
||||||
|
if (tok1->str() == "!")
|
||||||
|
tok1 = tok1->next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// dereference in function call (but not sizeof|decltype)
|
// dereference in function call (but not sizeof|decltype)
|
||||||
|
|
|
@ -231,6 +231,14 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 5\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 5\n", errout.str());
|
||||||
|
|
||||||
|
check("void f(ABC *abc) {\n"
|
||||||
|
" if (abc->x == 0) {\n"
|
||||||
|
" return;\n"
|
||||||
|
" }\n"
|
||||||
|
" if (!abc);\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 5\n", errout.str());
|
||||||
|
|
||||||
// TODO: False negative if member of member is dereferenced
|
// TODO: False negative if member of member is dereferenced
|
||||||
check("void foo(ABC *abc) {\n"
|
check("void foo(ABC *abc) {\n"
|
||||||
" abc->next->a = 0;\n"
|
" abc->next->a = 0;\n"
|
||||||
|
|
Loading…
Reference in New Issue