From 8c729fefa817f4366843d1eb16252e8515a11ea8 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:14:17 +0100 Subject: [PATCH] Fix #12394 FP uninitvar with reference to first array struct element (#6008) --- lib/astutils.cpp | 2 +- test/testuninitvar.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a242352a879..b3a656bdf02 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2571,7 +2571,7 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, tok2 = skipRedundantPtrOp(tok2, tok2->astParent()); if (tok2->astParent() && tok2->astParent()->isAssignmentOp()) { - if ((indirect == 0 || tok2 != tok) && tok2 == tok2->astParent()->astOperand1()) + if (((indirect == 0 || tok2 != tok) || (indirect == 1 && tok2->str() == ".")) && tok2 == tok2->astParent()->astOperand1()) return true; // Check if assigning to a non-const lvalue const Variable * var = getLHSVariable(tok2->astParent()); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index cd430663354..2fe099b08f5 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6406,6 +6406,14 @@ class TestUninitVar : public TestFixture { " f(&b);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + valueFlowUninit("struct S { int x; };\n" // #12394 + "int f() {\n" + " struct S s[1];\n" + " s->x = 0;\n" + " return s[0].x;\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value