Skip to content

Commit 81aa115

Browse files
committed
C++: Fix range analysis bug for 'RemExpr'.
1 parent dc2eea5 commit 81aa115

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

cpp/ql/src/semmle/code/cpp/rangeanalysis/SimpleRangeAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ private float getUpperBoundsImpl(Expr expr) {
10641064
// absolute value. Since `abs(x) = max(-x,x)` this is equivalent to
10651065
// adding `-rhsLB` to the set of upper bounds.
10661066
exists(float rhsLB |
1067-
rhsLB = getFullyConvertedLowerBounds(remExpr.getAnOperand()) and
1067+
rhsLB = getFullyConvertedLowerBounds(remExpr.getRightOperand()) and
10681068
not rhsLB >= 0
10691069
|
10701070
result = -rhsLB

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/lowerBound.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@
593593
| test.c:658:7:658:7 | u | 0 |
594594
| test.c:659:9:659:9 | u | 0 |
595595
| test.c:664:12:664:12 | s | -2147483648 |
596-
| test.c:665:7:665:8 | s2 | -2147483648 |
596+
| test.c:665:7:665:8 | s2 | -5 |
597597
| test.cpp:10:7:10:7 | b | -2147483648 |
598598
| test.cpp:11:5:11:5 | x | -2147483648 |
599599
| test.cpp:13:10:13:10 | x | -2147483648 |

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,5 +662,5 @@ void guard_bound_out_of_range(void) {
662662

663663
void test_mod(int s) {
664664
int s2 = s % 5;
665-
out(s2); // -4 .. 4 [BUG: is -max .. max]
665+
out(s2); // -4 .. 4 [BUG: is -5 .. 5]
666666
}

cpp/ql/test/library-tests/rangeanalysis/SimpleRangeAnalysis/upperBound.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@
593593
| test.c:658:7:658:7 | u | 0 |
594594
| test.c:659:9:659:9 | u | 4294967295 |
595595
| test.c:664:12:664:12 | s | 2147483647 |
596-
| test.c:665:7:665:8 | s2 | 2147483647 |
596+
| test.c:665:7:665:8 | s2 | 5 |
597597
| test.cpp:10:7:10:7 | b | 2147483647 |
598598
| test.cpp:11:5:11:5 | x | 2147483647 |
599599
| test.cpp:13:10:13:10 | x | 2147483647 |

0 commit comments

Comments
 (0)