diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 169df0b68..fd5585cdd 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1461,7 +1461,7 @@ static std::vector minUnsignedValue(const Token* tok, int depth return result; if (tok->hasKnownIntValue()) { result = {tok->values().front().intvalue}; - } else if (tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) { + } else if (tok->str() != "-" && tok->isConstOp() && tok->astOperand1() && tok->astOperand2()) { std::vector op1 = minUnsignedValue(tok->astOperand1(), depth - 1); std::vector op2 = minUnsignedValue(tok->astOperand2(), depth - 1); if (!op1.empty() && !op2.empty()) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index c431fcf91..90f661ec1 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -3620,6 +3620,12 @@ private: " g(name);\n" "}\n"); ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'name.empty()' is always true\n", errout.str()); + + // #10278 + check("void foo(unsigned int x) {\n" + " if ((100 - x) > 0) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void alwaysTrueInfer() {