diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 082030325..b1d70ea4e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -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; } } } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 66505bfae..89d19c5cb 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -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() {