From 4654b6561b61b8d80ea15edb688aa2f8dce3fb35 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Aug 2023 10:35:33 +0200 Subject: [PATCH] Fix #11890 FP uninitvar for address taken in init list (#5360) --- lib/astutils.cpp | 2 +- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0d9b6b78b..62204a9a0 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -3149,7 +3149,7 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings } else if (ftok->isControlFlowKeyword()) { return ExprUsage::Used; } else if (ftok->str() == "{") { - return ExprUsage::Used; + return indirect == 0 ? ExprUsage::Used : ExprUsage::Inconclusive; } else { const bool isnullbad = settings->library.isnullargbad(ftok, argnr + 1); if (indirect == 0 && astIsPointer(tok) && !addressOf && isnullbad) diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 9cc8b5030..c8b02fca4 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -6197,6 +6197,12 @@ private: " x = i;\n" "}\n"); ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: i\n", errout.str()); + + valueFlowUninit("void f() {\n" // #11890 + " int x;\n" + " int* a[] = { &x };\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void valueFlowUninitBreak() { // Do not show duplicate warnings about the same uninitialized value