From bfb1bc50e3b9afc91fd7866961bffbd8f1664850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Thu, 2 May 2013 20:34:15 +0200 Subject: [PATCH] Fixed #4760 (false negative: (error) usage of uninitialized variable (struct member)) --- lib/checkuninitvar.cpp | 2 ++ test/testuninitvar.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index a69351727..960a22016 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1616,6 +1616,8 @@ bool CheckUninitVar::isMemberVariableAssignment(const Token *tok, const std::str return true; else if ((tok->previous() && tok->previous()->isConstOp()) || Token::Match(tok->previous(), "[|=")) ; // member variable usage + else if (tok->tokAt(3)->isConstOp()) + ; // member variable usage else return true; } else if (tok->strAt(1) == "=") diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index b1ad18d24..dfa6b30b2 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2713,6 +2713,13 @@ private: "}\n", "test.c"); ASSERT_EQUALS("[test.c:9]: (error) Uninitialized struct member: fred.b\n", errout.str()); + checkUninitVar2("struct Fred { int a; };\n" + "void f() {\n" + " struct Fred fred;\n" + " if (fred.a==1) {}\n" + "}", "test.c"); + ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: fred.a\n", errout.str()); + checkUninitVar2("struct S { int n; int m; };\n" "void f(void) {\n" " struct S s;\n"