Fixed #2299 (false positive: possible nullpointer dereference)
This commit is contained in:
parent
845d1491f9
commit
696550abd3
|
@ -315,7 +315,21 @@ void CheckNullPointer::nullPointerStructByDeRefAndChec()
|
|||
else if (Token::Match(tok1->tokAt(-2), "%var% ( %var% . %var%") ||
|
||||
Token::Match(tok1->previous(), ", %var% . %var%"))
|
||||
{
|
||||
|
||||
// Is the function return value taken by the pointer?
|
||||
bool assignment = false;
|
||||
const unsigned int varid1(tok1->varId());
|
||||
const Token *tok2 = tok1->previous();
|
||||
while (tok2 && !Token::Match(tok2, "[;{}]"))
|
||||
{
|
||||
if (Token::Match(tok2, "%varid% =", varid1))
|
||||
{
|
||||
assignment = true;
|
||||
break;
|
||||
}
|
||||
tok2 = tok2->previous();
|
||||
}
|
||||
if (assignment)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Goto next token
|
||||
|
@ -399,6 +413,11 @@ void CheckNullPointer::nullPointerByDeRefAndChec()
|
|||
|
||||
for (const Token *tok1 = tok->previous(); tok1 && tok1 != decltok; tok1 = tok1->previous())
|
||||
{
|
||||
if (tok1->str() == ")" && Token::Match(tok1->link()->tokAt(-3), "%varid% = %var%", varid))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (tok1->varId() == varid)
|
||||
{
|
||||
bool unknown = false;
|
||||
|
|
|
@ -387,6 +387,14 @@ private:
|
|||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
check("void foo(x *p)\n"
|
||||
"{\n"
|
||||
" p = bar(p->next);\n"
|
||||
" if (!p)\n"
|
||||
" ;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer5()
|
||||
|
|
Loading…
Reference in New Issue