From ded2e68c2ea3c5c813adf33e776ca062d486db41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 29 Nov 2009 19:23:31 +0100 Subject: [PATCH] Fix #1022 (False positive: uninitialized variable when using local struct) --- lib/checkother.cpp | 7 +++++++ test/testother.cpp | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 04d0f54db..1d7eb8c00 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -1458,6 +1458,13 @@ void CheckOther::uninitvar() unsigned int indentlevel = 0; for (; tok; tok = tok->next()) { + // skip structs + if (Token::Match(tok->previous(), "[;{}] struct %var% {")) + { + tok = tok->tokAt(2)->link(); + continue; + } + if (tok->str() == "{") ++indentlevel; else if (tok->str() == "}") diff --git a/test/testother.cpp b/test/testother.cpp index aa14b8475..8dacf4722 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -1229,6 +1229,18 @@ private: " char *s2 = new char[strlen(s1)];\n" "};\n"); ASSERT_EQUALS("[test.cpp:4]: (error) Data is allocated but not initialized: s1\n", errout.str()); + + // struct.. + checkUninitVar("void f()\n" + "{\n" + " struct Relative {\n" + " Surface *surface;\n" + " void MoveTo(int x, int y) {\n" + " surface->MoveTo();\n" + " }\n" + " };\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); }