From 5bac8eca3728c715e61b8c3a9197d58d6941308e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 26 Dec 2011 22:14:52 +0100 Subject: [PATCH] Uninitialized variables: Fixed false positives (caused by my 'check more variables' commit) --- lib/checkuninitvar.cpp | 11 +++++++---- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 92135d2b4..d88676efc 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1059,12 +1059,15 @@ void CheckUninitVar::check() stdtype = true; else if (tok->str() == "*") pointer = true; - else if (tok->isName() && tok->next()->str() == ";") { - if (stdtype || pointer || _tokenizer->isC()) + else if (Token::Match(tok, "struct %type%")) + tok = tok->next(); + else { + if (tok->isName() && tok->next()->str() == ";" && + (stdtype || pointer)) { checkScopeForVariable(tok->next(), tok->varId(), pointer, NULL); + } break; - } else if (!tok->isName()) - break; + } tok = tok->next(); } } diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 1f15ea6d4..22c691a9a 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -1739,6 +1739,12 @@ private: "}"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: abc\n", errout.str()); + checkUninitVar2("int f() {\n" + " static int x;\n" + " return ++x;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // using uninit var in condition checkUninitVar2("void f() {\n" " int x;\n"