Fixed #1726 (False negative: null pointer dereference in switch block)

This commit is contained in:
Daniel Marjamäki 2010-06-06 12:15:31 +02:00
parent e140ff6e84
commit 472bd9dabe
2 changed files with 15 additions and 0 deletions

View File

@ -2488,6 +2488,14 @@ private:
/** parse condition. @sa ExecutionPath::parseCondition */ /** parse condition. @sa ExecutionPath::parseCondition */
bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks) bool parseCondition(const Token &tok, std::list<ExecutionPath *> &checks)
{ {
for (const Token *tok2 = &tok; tok2; tok2 = tok2->next())
{
if (tok2->str() == "(" || tok2->str() == ")")
break;
if (Token::Match(tok2, "[<>=] * %var%"))
dereference(checks, tok2->tokAt(2));
}
if (Token::Match(&tok, "!| %var% (")) if (Token::Match(&tok, "!| %var% ("))
{ {
std::list<const Token *> var; std::list<const Token *> var;

View File

@ -1041,6 +1041,13 @@ private:
"}\n"); "}\n");
ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str()); ASSERT_EQUALS("[test.cpp:7]: (error) Possible null pointer dereference: c\n", errout.str());
checkNullPointer("static void foo()\n"
"{\n"
" int *p = 0;\n"
" if (3 > *p);\n"
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Possible null pointer dereference: p\n", errout.str());
checkNullPointer("void f()\n" checkNullPointer("void f()\n"
"{\n" "{\n"
" if (x) {\n" " if (x) {\n"