diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 57a2f9e22..e0f837a1b 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -1532,8 +1532,12 @@ void CheckUninitVar::valueFlowUninit() const bool isarray = !tok->variable() || tok->variable()->isArray(); const bool ispointer = astIsPointer(tok) && !isarray; const bool deref = CheckNullPointer::isPointerDeRef(tok, unknown, mSettings); - if (ispointer && v->indirect == 1 && !deref) - continue; + if (ispointer && !deref) { + if (v->indirect >= 1) + continue; + if (!isVariableUsage(tok, true, NO_ALLOC, 0)) + continue; + } if (isarray && !deref) continue; uninitderef = deref && v->indirect == 0; diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 475733207..f5c2e6d22 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4474,14 +4474,12 @@ private: "}"); ASSERT_EQUALS("", errout.str()); - valueFlowUninit("int a(FArchive &arc) {\n" + valueFlowUninit("int a(FArchive &arc) {\n" // #3060 (initialization through operator<<) " int *p;\n" " arc << p;\n" - " return *p;\n" + " return *p;\n" // fp: should not warn "}"); - ASSERT_EQUALS("[test.cpp:3]: (error) Uninitialized variable: p\n" - "[test.cpp:4]: (error) Uninitialized variable: p\n", - errout.str()); + TODO_ASSERT_EQUALS("", "[test.cpp:4]: (error) Uninitialized variable: p\n", errout.str()); // #4320 valueFlowUninit("void f() {\n" @@ -4603,6 +4601,12 @@ private: "}"); ASSERT_EQUALS("", errout.str()); + valueFlowUninit("void foo(struct qb_list_head *list) {\n" + " struct qb_list_head *iter;\n" + " qb_list_for_each(iter, list) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + valueFlowUninit("int foo()\n" "{\n" " int i;\n"