Skip to content

Commit 24da4cc

Browse files
authored
Merge pull request #4421 from jbj/SimpleRangeAnalysis-guard-overflow
C++: Demonstrate overflowing guard bounds
2 parents 8eb84b2 + 0459248 commit 24da4cc

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@
588588
| test.c:646:18:646:18 | s | 0 |
589589
| test.c:646:22:646:22 | s | 0 |
590590
| test.c:647:9:647:14 | result | 0 |
591+
| test.c:653:7:653:7 | i | 0 |
592+
| test.c:654:9:654:9 | i | -2147483648 |
593+
| test.c:658:7:658:7 | u | 0 |
594+
| test.c:659:9:659:9 | u | 0 |
591595
| test.cpp:10:7:10:7 | b | -2147483648 |
592596
| test.cpp:11:5:11:5 | x | -2147483648 |
593597
| test.cpp:13:10:13:10 | x | -2147483648 |

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,4 +646,16 @@ void widen_recursive_expr() {
646646
int result = s + s; // 0 .. 9 [BUG: upper bound is 15 due to widening]
647647
out(result); // 0 .. 18 [BUG: upper bound is 127 due to double widening]
648648
}
649-
}
649+
}
650+
651+
void guard_bound_out_of_range(void) {
652+
int i = 0;
653+
if (i < 0) {
654+
out(i); // unreachable [BUG: is -max .. +max]
655+
}
656+
657+
unsigned int u = 0;
658+
if (u < 0) {
659+
out(u); // unreachable [BUG: is 0 .. +max]
660+
}
661+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,10 @@
588588
| test.c:646:18:646:18 | s | 15 |
589589
| test.c:646:22:646:22 | s | 15 |
590590
| test.c:647:9:647:14 | result | 127 |
591+
| test.c:653:7:653:7 | i | 0 |
592+
| test.c:654:9:654:9 | i | 2147483647 |
593+
| test.c:658:7:658:7 | u | 0 |
594+
| test.c:659:9:659:9 | u | 4294967295 |
591595
| test.cpp:10:7:10:7 | b | 2147483647 |
592596
| test.cpp:11:5:11:5 | x | 2147483647 |
593597
| test.cpp:13:10:13:10 | x | 2147483647 |

0 commit comments

Comments
 (0)