From 210232d35c117b0d70f7c3284089e04db54051c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Tue, 29 Oct 2019 20:36:58 +0100 Subject: [PATCH] Fixed #9314 (false positive: (error) Uninitialized variable: ret) --- lib/checkuninitvar.cpp | 8 ++++++++ test/testuninitvar.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/checkuninitvar.cpp b/lib/checkuninitvar.cpp index 2d7ef9e2b..91e7ef56a 100644 --- a/lib/checkuninitvar.cpp +++ b/lib/checkuninitvar.cpp @@ -244,6 +244,14 @@ static void conditionAlwaysTrueOrFalse(const Token *tok, const std::maphasKnownIntValue()) { + if (tok->getKnownIntValue() == 0) + *alwaysFalse = true; + else + *alwaysTrue = true; + return; + } + if (tok->isName() || tok->str() == ".") { while (tok && tok->str() == ".") tok = tok->astOperand2(); diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index bcc6e212a..3bc79ddd8 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -790,6 +790,14 @@ private: "}"); ASSERT_EQUALS("[test.cpp:6]: (error) Uninitialized variable: a\n", errout.str()); + checkUninitVar("int foo() {\n" + " int i;\n" + " if (1)\n" + " i = 11;\n" + " return i;\n" + "}"); + ASSERT_EQUALS("", errout.str()); + checkUninitVar("int foo()\n" "{\n" " int i;\n"