diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 6d93cc491..5d12dd0e2 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1346,6 +1346,8 @@ bool CheckUninitVar::checkScopeForVariable(const Scope* scope, const Token *tok, if (Token::Match(tok, "%var% . %var%") && tok->strAt(2) == membervar) { if (Token::Match(tok->tokAt(3), "[=.[]")) return true; + else if (Token::Match(tok->tokAt(-2), "[(,=] &")) + return true; else if (Token::Match(tok->previous(), "%op%") || Token::Match(tok->previous(), "[|=")) uninitStructMemberError(tok, tok->str() + "." + membervar); else diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 809af9933..a12e41848 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -2578,6 +2578,13 @@ private: "}\n", "test.c", true); ASSERT_EQUALS("[test.c:4]: (error) Uninitialized struct member: ab.a\n", errout.str()); + checkUninitVar2("struct AB { int a; int b; };\n" // pass struct member by address + "void f(void) {\n" + " struct AB ab;\n" + " assign(&ab.a, 0);\n" + "}\n", "test.c", true); + ASSERT_EQUALS("", errout.str()); + checkUninitVar2("struct AB { int a; int b; };\n" "void do_something(const struct AB ab);\n" "void f(void) {\n"