Fixed #2052 (False positive: possible null pointer dereference 'else continue')

This commit is contained in:
Daniel Marjamäki 2010-09-18 14:56:07 +02:00
parent 334cbbcbf8
commit de3c761790
2 changed files with 15 additions and 1 deletions

View File

@ -427,7 +427,10 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
}
// return/throw ends all execution paths
if (tok->str() == "return" || tok->str() == "throw")
if (tok->str() == "return" ||
tok->str() == "throw" ||
tok->str() == "continue" ||
tok->str() == "break")
{
ExecutionPath::bailOut(checks);
}

View File

@ -1057,6 +1057,17 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:12]: (error) Possible null pointer dereference: Q\n", errout.str());
// Ticket #2052 (false positive for 'else continue;')
checkNullPointer("void f() {\n"
" for (int x = 0; x < 5; ++x) {"
" int *p = 0;\n"
" if (a(x)) p=b(x);\n"
" else continue;\n"
" *p = 0;\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
// function pointer..
checkNullPointer("void foo()\n"
"{\n"