From d2d7e25f3ff211d7eec5af274885fe4b39c44e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Dec 2011 20:48:26 +0100 Subject: [PATCH] Uninitialized variables: Fixed false positive in for condition. Ticket: #3369 --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 19b777068..fe8a4a32d 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1124,7 +1124,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int } // TODO: handle loops, try, etc - if (Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) { + if (tok->str() == "for" || Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) { return true; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 197f90401..d04dac821 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1792,6 +1792,14 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + checkUninitVar2("void f() {\n" + " int x;\n" + " for (int i = 0; i < 10; i += x) {\n" + " x = y;\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // try checkUninitVar2("void f() {\n" " int i, *p = &i;\n"