Skip to content

Commit 49f7cd2

Browse files
Fix #14848 FP compareValueOutOfTypeRangeError and knownConditionTrueFalse with unsigned arithmetic (cppcheck-opensource#8658)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent 3122205 commit 49f7cd2

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

lib/vf_settokenvalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ namespace ValueFlow
613613
}
614614

615615
// unary minus
616-
else if (parent->isUnaryOp("-")) {
616+
else if (parent->isUnaryOp("-") && !astIsUnsigned(parent)) {
617617
for (const Value &val : tok->values()) {
618618
if (!val.isIntValue() && !val.isFloatValue())
619619
continue;

test/testvalueflow.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,12 @@ class TestValueFlow : public TestFixture {
12691269
ASSERT_EQUALS(1U, values.size());
12701270
ASSERT_EQUALS(-10, values.back().intvalue);
12711271

1272+
code = "bool f(unsigned a) {\n" // #14848
1273+
" bool x = -a < 1;\n"
1274+
" return x;\n"
1275+
"}";
1276+
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 1));
1277+
12721278
// Logical and
12731279
code = "void f(bool b) {\n"
12741280
" bool x = false && b;\n"

0 commit comments

Comments
 (0)