diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index db48285df..77721e01a 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -86,6 +86,9 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog } const ValueFlow::Value val(tok, num); + ValueFlow::Value val2; + if (num==1 && var->typeStartToken()->isUnsigned() && Token::Match(tok,"<=|>=")) + val2 = ValueFlow::Value(tok,0); for (Token *tok2 = tok->previous(); ; tok2 = tok2->previous()) { if (!tok2) { @@ -117,6 +120,8 @@ static void valueFlowBeforeCondition(TokenList *tokenlist, ErrorLogger *errorLog } tok2->values.push_back(val); + if (val2.condition) + tok2->values.push_back(val2); if (var && tok2 == var->nameToken()) break; } diff --git a/test/testother.cpp b/test/testother.cpp index ac7e2c5ec..0ede33824 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -210,6 +210,7 @@ private: settings->inconclusive = inconclusive; settings->experimental = experimental; settings->standards.posix = posix; + settings->valueFlow = true; if (posix) { const char cfg[] = "\n" diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 71904b601..bffbdedca 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -84,6 +84,13 @@ private: "}"; ASSERT_EQUALS(true, testValueOfX(code, 2U, 123)); + code = "void f(unsigned int x) {\n" + " int a = x;\n" + " if (x >= 1) {}\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 2U, 1)); + ASSERT_EQUALS(true, testValueOfX(code, 2U, 0)); + // bailout: ?: bailout("void f(int x) {\n" " y = ((x<0) ? x : ((x==2)?3:4));\n"