Fixed #2647 (False positive: Possible null pointer dereference (member function call))
This commit is contained in:
parent
6bd56dbe20
commit
f3728c0b76
|
@ -418,6 +418,16 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
|
||||||
if (var && (var->isLocal() || var->isArgument()))
|
if (var && (var->isLocal() || var->isArgument()))
|
||||||
isLocal = true;
|
isLocal = true;
|
||||||
|
|
||||||
|
// member function may or may not nullify the pointer if it's global (#2647)
|
||||||
|
if (!isLocal)
|
||||||
|
{
|
||||||
|
const Token *tok2 = tok1;
|
||||||
|
while (Token::Match(tok2, "%var% ."))
|
||||||
|
tok2 = tok2->tokAt(2);
|
||||||
|
if (Token::Match(tok2,"%var% ("))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// count { and } using tok2
|
// count { and } using tok2
|
||||||
unsigned int indentlevel2 = 0;
|
unsigned int indentlevel2 = 0;
|
||||||
for (const Token *tok2 = tok1->tokAt(3); tok2; tok2 = tok2->next())
|
for (const Token *tok2 = tok1->tokAt(3); tok2; tok2 = tok2->next())
|
||||||
|
|
|
@ -336,6 +336,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("",errout.str());
|
ASSERT_EQUALS("",errout.str());
|
||||||
|
|
||||||
|
check("Fred *fred;\n"
|
||||||
|
"void f() {\n"
|
||||||
|
" fred->foo();\n"
|
||||||
|
" if (fred) { }\n"
|
||||||
|
"}");
|
||||||
|
ASSERT_EQUALS("",errout.str());
|
||||||
|
|
||||||
// #2641 - local pointer, function call
|
// #2641 - local pointer, function call
|
||||||
check("void f() {\n"
|
check("void f() {\n"
|
||||||
" ABC *abc;\n"
|
" ABC *abc;\n"
|
||||||
|
|
Loading…
Reference in New Issue