Fixed #2300 (false positive: possible nullpointer dereference)

This commit is contained in:
Daniel Marjamäki 2010-12-16 21:41:50 +01:00
parent 49ee1533d9
commit 0cebcc8fa9
2 changed files with 12 additions and 2 deletions

View File

@ -497,8 +497,8 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
continue;
}
// abort function..
if (Token::simpleMatch(tok2, ") ; }") &&
// calling unknown function (abort/init)..
if (Token::simpleMatch(tok2, ") ;") &&
Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% ("))
{
break;

View File

@ -747,6 +747,16 @@ private:
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// ticket: #2300 - calling unknown function that may initialize the pointer
check("Fred *fred;\n"
"void a() {\n"
" if (!fred) {\n"
" initfred();\n"
" fred->x = 0;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
};