diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index d8a4b2260..bf09904b2 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -6786,6 +6786,9 @@ static void valueFlowUninit(TokenList* tokenlist, SymbolDatabase* /*symbolDataba for (const Variable& memVar : scope->varlist) { if (!memVar.isPublic()) continue; + // Skip array since we cant track partial initialization from nested subexpressions + if (memVar.isArray()) + continue; if (!needsInitialization(&memVar, tokenlist->isCPP())) { partial = true; continue; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 2848d6aa4..9be06e73b 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -5921,6 +5921,35 @@ private: " x = a.m;\n" "}"); ASSERT_EQUALS("", errout.str()); + + valueFlowUninit("struct S {\n" + " int t[1];\n" + "};\n" + "int f(const S* ps) {\n" + " return ps->t[0];\n" + "}\n" + "void g() {\n" + " S s;\n" + " s.t[0] = 1;\n" + " f(&s);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + valueFlowUninit("struct X {\n" + " int a, b;\n" + "};\n" + "struct S {\n" + " X t;\n" + "};\n" + "int f(const S* ps) {\n" + " return ps->t.a;\n" + "}\n" + "void g() {\n" + " S s;\n" + " s.t.a = 1;\n" + " f(&s);\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void uninitvar_memberfunction() {