Skip to content

Commit 7e929f8

Browse files
committed
Fix #14848 FP compareValueOutOfTypeRangeError and knownConditionTrueFalse with unsigned arithmetic
1 parent 051584c commit 7e929f8

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
@@ -1261,6 +1261,12 @@ class TestValueFlow : public TestFixture {
12611261
ASSERT_EQUALS(1U, values.size());
12621262
ASSERT_EQUALS(-10, values.back().intvalue);
12631263

1264+
code = "bool f(unsigned a) {\n"
1265+
" bool x = -a < 1;\n"
1266+
" return x;\n"
1267+
"}";
1268+
ASSERT_EQUALS(false, testValueOfXKnown(code, 3U, 1));
1269+
12641270
// Logical and
12651271
code = "void f(bool b) {\n"
12661272
" bool x = false && b;\n"

0 commit comments

Comments
 (0)