Fixed #2641 (False positive: Possible null pointer dereference (global pointer, function call))
This commit is contained in:
parent
29ab409af5
commit
0a28b7309f
|
@ -448,6 +448,15 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
|
|||
else if (indentlevel2 == 0 && tok2->str() == "return")
|
||||
break;
|
||||
|
||||
// Function call: If the pointer is a global variable it
|
||||
// might be changed by the call.
|
||||
// TODO: false negatives if the pointer is local.
|
||||
else if (Token::Match(tok2, "[;{}] %var% (") &&
|
||||
Token::simpleMatch(tok2->tokAt(2)->link(), ") ;"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// Check if pointer is null.
|
||||
// TODO: false negatives for "if (!p || .."
|
||||
else if (Token::Match(tok2, "if ( !| %varid% )|&&", varid1))
|
||||
|
|
|
@ -326,6 +326,15 @@ private:
|
|||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
// #2641 - global pointer, function call
|
||||
check("ABC *abc;\n"
|
||||
"void f() {\n"
|
||||
" abc->a = 0;\n"
|
||||
" do_stuff();\n"
|
||||
" if (abc) { }\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("",errout.str());
|
||||
}
|
||||
|
||||
// Dereferencing a pointer and then checking if it is null
|
||||
|
|
Loading…
Reference in New Issue