Fixed #2245 (False positive: Possible null pointer dereference)

This commit is contained in:
Daniel Marjamäki 2010-11-29 20:19:31 +01:00
parent 8b45a0e3b5
commit cdb685c83c
2 changed files with 16 additions and 1 deletions

View File

@ -490,6 +490,13 @@ void CheckNullPointer::nullPointerByCheckAndDeRef()
break; break;
} }
// parameters to sizeof are not dereferenced
if (Token::Match(tok2, "decltype|sizeof ("))
{
tok2 = tok2->next()->link();
continue;
}
// abort function.. // abort function..
if (Token::simpleMatch(tok2, ") ; }") && if (Token::simpleMatch(tok2, ") ; }") &&
Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% (")) Token::Match(tok2->link()->tokAt(-2), "[;{}] %var% ("))
@ -550,7 +557,7 @@ void CheckNullPointer::nullConstantDereference()
--indentlevel; --indentlevel;
} }
if (tok->str() == "(" && Token::simpleMatch(tok->previous(), "sizeof")) if (tok->str() == "(" && Token::Match(tok->previous(), "sizeof|decltype"))
tok = tok->link(); tok = tok->link();
else if (Token::simpleMatch(tok, "exit ( )")) else if (Token::simpleMatch(tok, "exit ( )"))

View File

@ -154,6 +154,14 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
// ticket #2245 - sizeof doesn't dereference
check("void f(Bar *p) {\n"
" if (!p) {\n"
" int sz = sizeof(p->x);\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
void nullpointer2() void nullpointer2()