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"