Fixed #1237 (Uninitialized variable false positive for return-value pattern in pan source code.)

This commit is contained in:
Daniel Marjamäki 2010-01-08 21:24:48 +01:00
parent 60ef3ef872
commit ca74f57fd0
2 changed files with 48 additions and 0 deletions

View File

@ -95,6 +95,13 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
return 0;
}
// .. ) { ... } => bail out
if (Token::simpleMatch(tok, ") {"))
{
ExecutionPath::bailOut(checks);
return 0;
}
if (Token::Match(tok, "abort|exit ("))
{
ExecutionPath::bailOut(checks);
@ -118,6 +125,19 @@ static const Token *checkExecutionPaths_(const Token *tok, std::list<ExecutionPa
continue;
}
// ; { ... }
if (Token::Match(tok->previous(), "[;{}] {"))
{
const Token *tokerr = checkExecutionPaths_(tok->next(), checks);
if (tokerr)
{
ExecutionPath::bailOut(checks);
return tokerr;
}
tok = tok->link();
continue;
}
if (tok->str() == "if")
{
std::list<ExecutionPath *> newchecks;

View File

@ -1587,6 +1587,34 @@ private:
" strchr(s.c_str(), ',');\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// ; { .. }
checkUninitVar("int foo()\n"
"{\n"
" int retval;\n"
" if (condition) {\n"
" { }\n"
" retval = 1; }\n"
" else\n"
" retval = 2;\n"
" return retval;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
// macro_for..
checkUninitVar("int foo()\n"
"{\n"
" int retval;\n"
" if (condition) {\n"
" for12(1,2) { }\n"
" retval = 1;\n"
" }\n"
" else\n"
" retval = 2;\n"
" return retval;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}