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

Skip to content

Commit 8cd6b51

Browse files
committed
Java: Add ConditionalExpr to overflow candidate pattern.
1 parent 39a45ce commit 8cd6b51

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

java/ql/src/Likely Bugs/Comparison/UselessComparisonTest.ql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ Expr overFlowCand() {
132132
result.(AssignExpr).getRhs() = overFlowCand()
133133
or
134134
result.(LocalVariableDeclExpr).getInit() = overFlowCand()
135+
or
136+
exists(ConditionalExpr c | c = result |
137+
c.getTrueExpr() = overFlowCand() and
138+
c.getFalseExpr() = overFlowCand()
139+
)
135140
}
136141

137142
predicate positiveOrNegative(Expr e) { positive(e) or negative(e) }

java/ql/test/query-tests/UselessComparisonTest/A.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ void overflowTests(int x, int y) {
121121
}
122122
}
123123

124+
void overflowTests2(int[] a, boolean b) {
125+
int newlen = b ? (a.length + 1) << 1 : (a.length >> 1) + a.length;
126+
if (newlen < 0) overflow();
127+
}
128+
124129
static final long VAL = 100L;
125130

126131
long overflowAwareIncrease(long x) {

0 commit comments

Comments
 (0)