Fixed #1855 (false positive: uninitialized variable (function call in switch condition))

This commit is contained in:
Daniel Marjamäki 2010-07-18 13:19:37 +02:00
parent 020a8a965c
commit 1fb4758583
2 changed files with 19 additions and 0 deletions

View File

@ -192,6 +192,13 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
if (tok->str() == "switch") if (tok->str() == "switch")
{ {
// parse condition
if (checks.size() > 10 || check->parseCondition(*tok->next(), checks))
{
ExecutionPath::bailOut(checks);
return;
}
const Token *tok2 = tok->next()->link(); const Token *tok2 = tok->next()->link();
if (Token::simpleMatch(tok2, ") { case")) if (Token::simpleMatch(tok2, ") { case"))
{ {

View File

@ -1834,6 +1834,18 @@ private:
" } catch (...) {\n" " } catch (...) {\n"
" }\n" " }\n"
"}\n"); "}\n");
// #1855 - switch(foo(&x))
checkUninitVar("int a()\n"
"{\n"
" int x;\n"
" switch (foo(&x))\n"
" {\n"
" case 1:\n"
" return x;\n"
" }\n"
"}\n");
ASSERT_EQUALS("", errout.str());
} }
// arrays.. // arrays..