Null pointers: Fixed false negative for such code: 'abc->a = 0; if (abc && ..'. Ticket: #2379
This commit is contained in:
parent
e7ef1b3627
commit
29d05cf5f2
|
@ -444,8 +444,8 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
|
|||
break;
|
||||
|
||||
// Check if pointer is null.
|
||||
// TODO: false negatives for something like: "if (p &&.."?
|
||||
else if (Token::Match(tok2, "if ( !| %varid% )", varid1))
|
||||
// TODO: false negatives for "if (!p || .."
|
||||
else if (Token::Match(tok2, "if ( !| %varid% )|&&", varid1))
|
||||
{
|
||||
// Is this variable a pointer?
|
||||
if (isPointer(varid1))
|
||||
|
|
|
@ -215,6 +215,13 @@ private:
|
|||
"}\n");
|
||||
TODO_ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 3\n", "", errout.str());
|
||||
|
||||
check("void foo(ABC *abc) {\n"
|
||||
" abc->a = 0;\n"
|
||||
" if (abc && abc->b == 0)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Possible null pointer dereference: abc - otherwise it is redundant to check if abc is null at line 3\n", errout.str());
|
||||
|
||||
// ok dereferencing in a condition
|
||||
check("void foo(struct ABC *abc)\n"
|
||||
"{\n"
|
||||
|
|
Loading…
Reference in New Issue