Fixed #5664 (false positive: (error) Uninitialized variable: j (Comma operator in for loop))

This commit is contained in:
Daniel Marjamäki 2014-04-21 10:32:29 +02:00
parent 442b272b3f
commit 04cd261ee2
2 changed files with 11 additions and 1 deletions

View File

@ -1602,7 +1602,7 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
bool assign = true;
if (tok->strAt(1) == "=") {
unsigned int indentlevel = 0; // Handle '(a=1)..'
for (const Token *tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) {
for (const Token *tok2 = tok->next(); tok2; tok2 = tok2->next()) {
if (tok2->varId() == var.declarationId()) {
assign = false;
break;
@ -1615,6 +1615,8 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const
if (indentlevel <= 1U)
break;
--indentlevel;
} else if (tok2->str() == ";" || tok2->str() == ",") {
break;
}
}
}

View File

@ -3274,6 +3274,14 @@ private:
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
checkUninitVar2("void f(void) {\n"
" int i;\n"
" while (x) {\n"
" for (i=0,y=i;;){}\n"
" }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void uninitvar2_4494() {