Skip to content

Commit 27b8a46

Browse files
committed
Java: Exclude loop conditions from overflow check heuristic.
1 parent 066a2f0 commit 27b8a46

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,14 @@ Expr increaseOrDecreaseOfVar(SsaVariable v) {
168168
}
169169

170170
predicate overFlowTest(ComparisonExpr comp) {
171-
exists(SsaVariable v | comp.hasOperands(increaseOrDecreaseOfVar(v), v.getAUse()))
172-
or
173-
comp.getLesserOperand() = overFlowCand() and
174-
comp.getGreaterOperand().(IntegerLiteral).getIntValue() = 0
171+
(
172+
exists(SsaVariable v | comp.hasOperands(increaseOrDecreaseOfVar(v), v.getAUse()))
173+
or
174+
comp.getLesserOperand() = overFlowCand() and
175+
comp.getGreaterOperand().(IntegerLiteral).getIntValue() = 0
176+
) and
177+
// exclude loop conditions as they are unlikely to be overflow tests
178+
not comp.getEnclosingStmt() instanceof LoopStmt
175179
}
176180

177181
predicate concurrentModificationTest(BinaryExpr test) {

0 commit comments

Comments
 (0)