Merge pull request #2305 from aschackmull/java/overflowcheck-conditionalexpr

Java: Add ConditionalExpr to overflow candidate pattern.
This commit is contained in:
yh-semmle
2019-11-12 16:32:09 -05:00
committed by GitHub
2 changed files with 10 additions and 0 deletions

View File

@@ -132,6 +132,11 @@ Expr overFlowCand() {
result.(AssignExpr).getRhs() = overFlowCand()
or
result.(LocalVariableDeclExpr).getInit() = overFlowCand()
or
exists(ConditionalExpr c | c = result |
c.getTrueExpr() = overFlowCand() and
c.getFalseExpr() = overFlowCand()
)
}
predicate positiveOrNegative(Expr e) { positive(e) or negative(e) }

View File

@@ -121,6 +121,11 @@ public class A {
}
}
void overflowTests2(int[] a, boolean b) {
int newlen = b ? (a.length + 1) << 1 : (a.length >> 1) + a.length;
if (newlen < 0) overflow();
}
static final long VAL = 100L;
long overflowAwareIncrease(long x) {