From 8bb4b1ac0d1f88dd9f6e2e7ed3b880456827bb40 Mon Sep 17 00:00:00 2001 From: chrchr Date: Wed, 18 Oct 2023 10:47:11 +0200 Subject: [PATCH] Fix #12082 FP uninitvar for assignment to array member in conditional --- lib/astutils.cpp | 2 ++ test/testuninitvar.cpp | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index f417ad704ff..df34edcac9c 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3232,6 +3232,8 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings if (!args.empty() && indirect == 0 && !addressOf) return ExprUsage::Used; } else if (ftok->isControlFlowKeyword()) { + if (Token::simpleMatch(ftok->astParent(), "(") && Token::simpleMatch(ftok->astParent()->astOperand2(), "=")) + return ExprUsage::Inconclusive; return ExprUsage::Used; } else if (ftok->str() == "{") { return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 6e4abe8d876..924a1e3c76c 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6288,7 +6288,14 @@ class TestUninitVar : public TestFixture { " int &q = s;\n" " foo(q);\n" "}\n"); - ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout.str()); + ASSERT_EQUALS("[test.cpp:9]: (error) Uninitialized variable: q\n", errout.str()); + + valueFlowUninit("int g();\n" // #12082 + "void f() {\n" + " int a[1];\n" + " while (a[0] = g()) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value