ExecutionPath: better handling of 'FOREACH(..){..}'
This commit is contained in:
parent
d3ed1c8960
commit
f41334e58a
|
@ -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, ") {"))
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue