diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 3659d84f9..1fa8d4d6e 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1407,8 +1407,12 @@ bool CheckUninitVar::checkIfForWhileHead(const Token *startparentheses, const Va for (const Token *tok = startparentheses->next(); tok && tok != endpar; tok = tok->next()) { if (tok->varId() == var.varId()) { if (Token::Match(tok, "%var% . %var%")) { - if (tok->strAt(2) == membervar) - uninitStructMemberError(tok, tok->str() + "." + membervar); + if (tok->strAt(2) == membervar) { + if (tok->strAt(3) == "=") + return true; + else + uninitStructMemberError(tok, tok->str() + "." + membervar); + } continue; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 4cd0e95d6..6802c2d6f 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2662,6 +2662,13 @@ private: " if (fred.b == 0) { }\n" "}\n", "test.c", true); ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout.str()); + + checkUninitVar2("struct S { int n; int m; };\n" + "void f(void) {\n" + " struct S s;\n" + " for (s.n = 0; s.n <= 10; s.n++) { }\n" + "}", "test.c"); + ASSERT_EQUALS("", errout.str()); } void uninitvar2_while() {