Merge pull request #2085 from aschackmull/java/overflow-check-fp

Java: Add another overflow check pattern to UselessComparisonTest.
This commit is contained in:
yh-semmle
2019-10-18 11:01:24 -04:00
committed by GitHub
3 changed files with 47 additions and 15 deletions

View File

@@ -121,6 +121,26 @@ public class A {
}
}
static final long VAL = 100L;
long overflowAwareIncrease(long x) {
if (x + VAL > x) {
return x + VAL;
} else {
overflow();
return Long.MAX_VALUE;
}
}
long overflowAwareDecrease(long x) {
if (x - VAL < x) {
return x - VAL;
} else {
overflow();
return Long.MIN_VALUE;
}
}
void overflow() { }
void unreachableCode() {