diff --git a/lib/vf_analyzers.cpp b/lib/vf_analyzers.cpp index 32b06eb96e4..cf92e8f578f 100644 --- a/lib/vf_analyzers.cpp +++ b/lib/vf_analyzers.cpp @@ -527,6 +527,8 @@ struct ValueFlowAnalyzer : Analyzer { continue; if (exact && v.intvalue != 0 && !isPoint) continue; + if (astIsUnsigned(tok) != astIsUnsigned(v.tokvalue)) + continue; std::vector r; ValueFlow::Value::Bound bound = currValue->bound; if (match(v.tokvalue)) { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index db2f41e6da2..5a3f5211bfa 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -4947,6 +4947,13 @@ class TestCondition : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void f(unsigned x) {\n" // #13522 + " unsigned u = x;\n" + " int i = u - 0;\n" + " if (i < 0) {}\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void alwaysTrueInfer() {