ExecutionPath: better handling of 'FOREACH(..){..}'

This commit is contained in:
Daniel Marjamäki 2010-05-30 08:26:44 +02:00
parent d3ed1c8960
commit f41334e58a
2 changed files with 31 additions and 0 deletions

View File

@ -157,6 +157,29 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
continue;
}
// bailout used variables in '; FOREACH ( .. ) { .. }'
else if (Token::Match(tok->previous(), "[;{}] %var% ("))
{
// goto {
const Token *tok2 = tok->tokAt(2);
if (tok2 && tok2->str() == "(")
tok2 = tok2->link();
if (tok2 && tok2->str() == ")")
tok2 = tok2->next();
if (tok2 && tok2->str() == "{")
{
// goto "}"
tok2 = tok2->link();
// bail out all variables used in "{ .. }"
for (; tok && tok != tok2; tok = tok->next())
{
if (tok->varId())
ExecutionPath::bailOutVar(checks, tok->varId());
}
}
}
// .. ) { ... } => bail out
if (Token::simpleMatch(tok, ") {"))
{

View File

@ -1374,6 +1374,14 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s\n", errout.str());
checkUninitVar("void a()\n"
"{\n"
" struct S *s;\n"
" FOREACH() { }\n"
" s->x = 0;\n"
"}\n");
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s\n", errout.str());
// #1533
checkUninitVar("char a()\n"
"{\n"