From e11dcc609be810bef38a80a420887c95cb59714f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 24 Jul 2019 18:20:23 +0200 Subject: [PATCH] Fixed #7758 (Function array is seen as Uninitialized) --- lib/checkuninitvar.cpp | 8 +++++++- test/testuninitvar.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 9891e27fe..600316d8f 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -150,7 +150,13 @@ void CheckUninitVar::checkScope(const Scope* scope, const std::set if (var.isArray()) { Alloc alloc = ARRAY; const std::map variableValue; - checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue); + bool init = false; + for (const Token *parent = var.nameToken(); parent; parent = parent->astParent()) { + if (parent->str() == "=") + init = true; + } + if (!init) + checkScopeForVariable(tok, var, nullptr, nullptr, &alloc, emptyString, variableValue); continue; } if (stdtype || var.isPointer()) { diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 2557aaaab..3f947cda5 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -4003,6 +4003,12 @@ private: " dostuff(*a);\n" "}"); ASSERT_EQUALS("", errout.str()); + + checkUninitVar("void f() {\n" + " void (*fp[1]) (void) = {function1};\n" + " (*fp[0])();\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void deadPointer() {