Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d9acbf

Browse files
committed
C++: Demonstrate overflowing guard bounds
1 parent 297f1c7 commit 1d9acbf

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@
582582
| test.c:635:9:635:10 | ss | -32768 |
583583
| test.c:638:7:638:8 | ss | -32768 |
584584
| test.c:639:9:639:10 | ss | -1 |
585+
| test.c:645:7:645:7 | i | 0 |
586+
| test.c:646:9:646:9 | i | -2147483648 |
587+
| test.c:650:7:650:7 | u | 0 |
588+
| test.c:651:9:651:9 | u | 0 |
585589
| test.cpp:10:7:10:7 | b | -2147483648 |
586590
| test.cpp:11:5:11:5 | x | -2147483648 |
587591
| 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
@@ -638,4 +638,16 @@ void two_bounds_from_one_test(short ss, unsigned short us) {
638638
if (ss + 1 < sizeof(int)) {
639639
out(ss); // -1 .. 2
640640
}
641-
}
641+
}
642+
643+
void guard_bound_out_of_range(void) {
644+
int i = 0;
645+
if (i < 0) {
646+
out(i); // 0 .. 0 [BUG: is -max .. +max]
647+
}
648+
649+
unsigned int u = 0;
650+
if (u < 0) {
651+
out(u); // 0 .. 0 [BUG: is 0 .. +max]
652+
}
653+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@
582582
| test.c:635:9:635:10 | ss | 32767 |
583583
| test.c:638:7:638:8 | ss | 32767 |
584584
| test.c:639:9:639:10 | ss | 2 |
585+
| test.c:645:7:645:7 | i | 0 |
586+
| test.c:646:9:646:9 | i | 2147483647 |
587+
| test.c:650:7:650:7 | u | 0 |
588+
| test.c:651:9:651:9 | u | 4294967295 |
585589
| test.cpp:10:7:10:7 | b | 2147483647 |
586590
| test.cpp:11:5:11:5 | x | 2147483647 |
587591
| test.cpp:13:10:13:10 | x | 2147483647 |

0 commit comments

Comments
 (0)