From 6221145be86eaec905f7f1c443a7c0871f96bd60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 15 Dec 2011 18:30:59 +0100 Subject: [PATCH] Fixed #3414 (false positive: (error) Uninitialized variable: SOutput) --- lib/checkuninitvar.cpp | 4 ++-- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index f66bf40ae..166c0c7e8 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1123,8 +1123,8 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const unsigned int } } - // TODO: handle loops etc - if (Token::simpleMatch(tok, ") {")) { + // TODO: handle loops, try, etc + if (Token::simpleMatch(tok, ") {") || Token::Match(tok, "%var% {")) { ret = true; return false; } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index d6e853931..25c82371e 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1784,6 +1784,13 @@ private: "}\n"); ASSERT_EQUALS("", errout.str()); + // try + checkUninitVar2("void f() {\n" + " int i, *p = &i;\n" + " try { }\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // exit checkUninitVar2("void f() {\n" " int x;\n"