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()); } };