From a4653a057a6ccbb0f344bc8ac780c4dd731bc891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 25 May 2021 20:37:22 +0200 Subject: [PATCH] Uninitialized variables; Fixed FP for range for loop --- lib/checkuninitvar.cpp | 2 ++ test/testuninitvar.cpp | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 65c1da3b5..d431f1d8a 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1528,6 +1528,8 @@ 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 443a7ec25..2aebecf42 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4639,6 +4639,13 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + // range for.. + valueFlowUninit("void f() {\n" + " X *item;\n" + " for (item: itemList) {}\n" + "}"); + ASSERT_EQUALS("", errout.str()); + // macro_for.. valueFlowUninit("int foo()\n" "{\n"