diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 0372041b9..7c1c39cf3 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1020,6 +1020,8 @@ static bool isVoidCast(const Token *tok) const Token* CheckUninitVar::isVariableUsage(const Token *vartok, bool pointer, Alloc alloc, int indirect) const { const Token *valueExpr = vartok; // non-dereferenced , no address of value as variable + while (Token::Match(valueExpr->astParent(), ".|::") && astIsRhs(valueExpr)) + valueExpr = valueExpr->astParent(); if (!pointer) { if (Token::Match(vartok, "%name% [.(]") && vartok->variable() && !vartok->variable()->isPointer() && vartok->variable()->isClass()) return nullptr; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 619573a03..efe6e0e0d 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4279,6 +4279,14 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + valueFlowUninit("struct AB { int a; int b; };\n" + "void f(void) {\n" + " AB ab;\n" + " AB *p = &ab;\n" + " p->a = 1;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // Unknown types { valueFlowUninit("void a()\n"