Fixed #1808 (false positive: uninitialized variable with multiple assignment)

This commit is contained in:
Robert Reif 2010-06-29 08:38:24 +02:00 committed by Daniel Marjamäki
parent 7f5239e96c
commit 4668359b51
2 changed files with 19 additions and 1 deletions

View File

@ -1301,8 +1301,13 @@ void CheckOther::functionVariableUsage()
variables.write(varid1);
}
const Token *equal = tok->next();
if (Token::Match(tok->next(), "[ %any% ]"))
equal = tok->tokAt(4);
// checked for chained assignments
if (tok != start && tok->next()->str() == "=")
if (tok != start && equal->str() == "=")
{
Variables::VariableUsage *var = variables.find(tok->varId());

View File

@ -68,6 +68,7 @@ private:
TEST_CASE(localvar20); // ticket #1799
TEST_CASE(localvar21); // ticket #1807
TEST_CASE(localvar22); // ticket #1811
TEST_CASE(localvar23); // ticket #1808
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639
@ -1203,6 +1204,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar23() // ticket #1808
{
functionVariableUsage("int foo(int c)\n"
"{\n"
" int a;\n"
" int b[10];\n"
" a = b[c] = 0;\n"
" return a;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1()
{
functionVariableUsage("void foo()\n"