From e0436098f8af7e5a6453f2b59214f1e19fc471ef Mon Sep 17 00:00:00 2001 From: chrchr Date: Mon, 26 Feb 2024 12:01:18 +0100 Subject: [PATCH] Fix #12473 FN uninitvar with pointer member (regression) --- lib/checkuninitvar.cpp | 2 +- test/testuninitvar.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 7b1a04cabd0..b1e8e0ccf1a 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1658,7 +1658,7 @@ void CheckUninitVar::valueFlowUninit() (!isVariableChangedByFunctionCall(v->tokvalue, v->indirect, mSettings, &inconclusive) || inconclusive)) continue; if (usage != ExprUsage::Used) { - if (!(Token::Match(tok->astParent(), ". %name% (") && uninitderef) && + if (!(Token::Match(tok->astParent(), ". %name% (|[") && uninitderef) && isVariableChanged(tok, v->indirect, mSettings, mTokenizer->isCPP())) continue; if (isVariableChangedByFunctionCall(tok, v->indirect, mSettings, &inconclusive) || inconclusive) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 2fe099b08f5..4da0ec4f086 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6414,6 +6414,13 @@ class TestUninitVar : public TestFixture { " return s[0].x;\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + valueFlowUninit("struct S { int* p; };\n" // #12473 + "void f() {\n" + " struct S s;\n" + " s.p[0] = 0;\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:4]: (error) Uninitialized variable: s.p\n", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value