ExecutionPath: Better handling of 'FOREACH (..) {}'
This commit is contained in:
parent
f41334e58a
commit
ab41879246
|
@ -158,13 +158,12 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
|
||||||
}
|
}
|
||||||
|
|
||||||
// bailout used variables in '; FOREACH ( .. ) { .. }'
|
// bailout used variables in '; FOREACH ( .. ) { .. }'
|
||||||
else if (Token::Match(tok->previous(), "[;{}] %var% ("))
|
else if (tok->str() != "if" && Token::Match(tok->previous(), "[;{}] %var% ("))
|
||||||
{
|
{
|
||||||
// goto {
|
// goto {
|
||||||
const Token *tok2 = tok->tokAt(2);
|
const Token *tok2 = tok->next()->link();
|
||||||
if (tok2 && tok2->str() == "(")
|
|
||||||
tok2 = tok2->link();
|
|
||||||
if (tok2 && tok2->str() == ")")
|
if (tok2 && tok2->str() == ")")
|
||||||
|
{
|
||||||
tok2 = tok2->next();
|
tok2 = tok2->next();
|
||||||
if (tok2 && tok2->str() == "{")
|
if (tok2 && tok2->str() == "{")
|
||||||
{
|
{
|
||||||
|
@ -179,6 +178,7 @@ static void checkExecutionPaths_(const Token *tok, std::list<ExecutionPath *> &c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// .. ) { ... } => bail out
|
// .. ) { ... } => bail out
|
||||||
if (Token::simpleMatch(tok, ") {"))
|
if (Token::simpleMatch(tok, ") {"))
|
||||||
|
|
|
@ -1382,6 +1382,15 @@ private:
|
||||||
"}\n");
|
"}\n");
|
||||||
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:5]: (error) Uninitialized variable: s\n", errout.str());
|
||||||
|
|
||||||
|
checkUninitVar("void a()\n"
|
||||||
|
"{\n"
|
||||||
|
" struct S *s1;\n"
|
||||||
|
" struct S *s2;\n"
|
||||||
|
" FOREACH(s1) { }\n"
|
||||||
|
" s2->x = 0;\n"
|
||||||
|
"}\n");
|
||||||
|
ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: s2\n", errout.str());
|
||||||
|
|
||||||
// #1533
|
// #1533
|
||||||
checkUninitVar("char a()\n"
|
checkUninitVar("char a()\n"
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
Loading…
Reference in New Issue