From 2265c617348370a56524424569376121d812b29c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 26 Jun 2013 17:02:57 +0200 Subject: [PATCH] Fixed #4879 (false positive: uninitialized variable in inner for inside while (regression)) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 8e4826ce2..0339715b5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1484,7 +1484,7 @@ bool CheckUninitVar::checkLoopBody(const Token *tok, const Variable& var, const } else { if (isVariableUsage(tok, var.isPointer(), _tokenizer->isCPP())) usetok = tok; - else if (Token::Match(tok->previous(), "[;{}] %var% =")) { + else if (tok->strAt(1) == "=") { bool assign = true; for (const Token *tok2 = tok->next(); tok2 && tok2->str() != ";"; tok2 = tok2->next()) { if (tok2->varId() == var.varId()) { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 3a64ed1fb..44efc54c0 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2919,6 +2919,15 @@ private: " x += sizeof(*abc);\n" "}"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar2("void f(void) {\n" // #4879 + " int i;\n" + " while (x) {\n" + " for (i = 0; i < 5; i++)\n" + " a[i] = b[i];\n" + " }\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void uninitvar2_4494() {