diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index 79524745d73..3c829b0955e 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -204,8 +204,10 @@ static bool evaluateCondition(const std::string& op, if (!condition) return false; if (condition->str() == op) { - return evaluateCondition(op, r, condition->astOperand1(), pm, settings) || - evaluateCondition(op, r, condition->astOperand2(), pm, settings); + if (evaluateCondition(op, r, condition->astOperand1(), pm, settings) || + evaluateCondition(op, r, condition->astOperand2(), pm, settings)) { + return true; + } } MathLib::bigint result = 0; bool error = false; @@ -309,8 +311,10 @@ void programMemoryParseCondition(ProgramMemory& pm, const Token* tok, const Toke if (lhs.empty() || rhs.empty()) { if (frontIs(lhs, !then)) programMemoryParseCondition(pm, tok->astOperand2(), endTok, settings, then); - if (frontIs(rhs, !then)) + else if (frontIs(rhs, !then)) programMemoryParseCondition(pm, tok->astOperand1(), endTok, settings, then); + else + pm.setIntValue(tok, 0, then); } } else if (tok->exprId() > 0) { if (endTok && isExpressionChanged(tok, tok->next(), endTok, settings, true)) diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 78d33a551d6..75f985e4339 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5605,6 +5605,22 @@ class TestValueFlow : public TestFixture { "}\n"; values = tokenValues(code, "x >", ValueFlow::Value::ValueType::UNINIT); ASSERT_EQUALS(0, values.size()); + + // #12031 + code = "bool g(int *p);\n" + "bool h();\n" + "void f(bool b, int y) {\n" + " int x;\n" + " if (b && y > 0) {\n" + " b = g(&x);\n" + " }\n" + " while (b && y > 0) {\n" + " if (x < 0) {}\n" + " break;\n" + " }\n" + "}\n"; + values = tokenValues(code, "x <", ValueFlow::Value::ValueType::UNINIT); + ASSERT_EQUALS(0, values.size()); } void valueFlowConditionExpressions() {