From 5f0fe1dfe72361080dc2f898c934d17eeee83317 Mon Sep 17 00:00:00 2001 From: Paul Fultz II Date: Tue, 25 May 2021 21:52:55 -0500 Subject: [PATCH] Fix another FP with range for macro (#3276) --- lib/astutils.cpp | 3 +++ lib/checkuninitvar.cpp | 2 -- test/testuninitvar.cpp | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 0329b66da..b0497ac70 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1909,6 +1909,9 @@ bool isVariableChanged(const Token *tok, int indirect, const Settings *settings, } if (Token::simpleMatch(tok2->astParent(), ":") && tok2->astParent()->astParent() && Token::simpleMatch(tok2->astParent()->astParent()->previous(), "for (")) { + // TODO: Check if container is empty or not + if (astIsLHS(tok2)) + return true; const Token * varTok = tok2->astParent()->previous(); if (!varTok) return false; diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index d431f1d8a..65c1da3b5 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1528,8 +1528,6 @@ void CheckUninitVar::valueFlowUninit() continue; if (v->indirect > 1 || v->indirect < 0) continue; - if (v->indirect == 0 && !isVariableUsage(tok, tok->valueType() && tok->valueType()->pointer > 0, NO_ALLOC)) - continue; bool uninitderef = false; if (tok->variable()) { bool unknown; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 2aebecf42..7948632f2 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4646,6 +4646,16 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + valueFlowUninit("X f() {\n" + " if (!itemList.empty()) {\n" + " X* item;\n" + " for(item: itemList) {}\n" + " return *item;\n" + " }\n" + " return X{};\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + // macro_for.. valueFlowUninit("int foo()\n" "{\n"