From 4a9984d73bab8a8cc3ea1e29014dd0d93d5b7dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 6 Nov 2017 10:28:07 +0100 Subject: [PATCH] Fixed #8233 (FP uninitvar found in bash:lib/readline/display.c) --- lib/valueflow.cpp | 10 +++++++++- test/testvalueflow.cpp | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 56d028e6e..20f6b9ce9 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1595,7 +1595,7 @@ static bool valueFlowForward(Token * const startToken, errorLogger, settings); - if (isVariableChanged(startToken1, startToken1->link(), varid, var->isGlobal(), settings)) { + if (!condAlwaysFalse && isVariableChanged(startToken1, startToken1->link(), varid, var->isGlobal(), settings)) { removeValues(values, truevalues); std::list::iterator it; @@ -1626,6 +1626,14 @@ static bool valueFlowForward(Token * const startToken, errorLogger, settings); + if (!condAlwaysTrue && isVariableChanged(startTokenElse, startTokenElse->link(), varid, var->isGlobal(), settings)) { + removeValues(values, falsevalues); + + std::list::iterator it; + for (it = values.begin(); it != values.end(); ++it) + it->changeKnownToPossible(); + } + // goto '}' tok2 = startTokenElse->link(); diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 3f1050c27..359793bb0 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -2730,6 +2730,19 @@ private: "}"; values = tokenValues(code, "n =="); ASSERT_EQUALS(true, values.size() != 1U || !values.front().isUninitValue()); + + // #8233 + code = "void foo() {\n" + " int x;\n" + " int y = 1;\n" + " if (y>1)\n" + " x = 1;\n" + " else\n" + " x = 1;\n" + " if (x>1) {}\n" + "}"; + values = tokenValues(code, "x >"); + ASSERT_EQUALS(true, values.size() == 1U && values.front().isIntValue()); } };