From 7ca35d181b681014008066f6befba9529a15ebec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 2 Jun 2019 20:19:53 +0200 Subject: [PATCH] uninitStructMember: Fixed FP shown in daca@home --- lib/checkuninitvar.cpp | 7 +++++-- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index ff10b8150..961103b7f 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1225,9 +1225,12 @@ bool CheckUninitVar::isMemberVariableUsage(const Token *tok, bool isPointer, All if (isMemberVariableAssignment(tok, membervar)) return false; - if (Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar && !(tok->tokAt(-2)->variable() && tok->tokAt(-2)->variable()->isReference())) + if (Token::Match(tok, "%name% . %name%") && tok->strAt(2) == membervar && !(tok->tokAt(-2)->variable() && tok->tokAt(-2)->variable()->isReference())) { + const Token *parent = tok->next()->astParent(); + if (parent && parent->isUnaryOp("&")) + return false; return true; - else if (!isPointer && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc)) + } else if (!isPointer && Token::Match(tok->previous(), "[(,] %name% [,)]") && isVariableUsage(tok, isPointer, alloc)) return true; else if (!isPointer && Token::Match(tok->previous(), "= %name% ;")) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 9b1169acf..100bf43a6 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -3358,6 +3358,13 @@ private: "[test.cpp:5]: (error) Uninitialized struct member: abc.b\n" "[test.cpp:5]: (error) Uninitialized struct member: abc.c\n", errout.str()); + checkUninitVar("struct ABC { int a; int b; int c; };\n" + "void foo() {\n" + " struct ABC abc;\n" + " dostuff((uint32_t *)&abc.a);\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // return checkUninitVar("struct AB { int a; int b; };\n" "void f(void) {\n"