Skip to content

Commit ca8fe03

Browse files
committed
Java: Improve join by preventing ssa use-pair join.
1 parent d64a936 commit ca8fe03

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

java/ql/src/Likely Bugs/Collections/ArrayIndexOutOfBounds.ql

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import semmle.code.java.dataflow.SSA
1818
import semmle.code.java.dataflow.RangeUtils
1919
import semmle.code.java.dataflow.RangeAnalysis
2020

21+
pragma[nomagic]
22+
predicate ssaArrayLengthBound(SsaVariable arr, Bound b) {
23+
exists(FieldAccess len |
24+
len.getField() instanceof ArrayLengthField and
25+
len.getQualifier() = arr.getAUse() and
26+
b.getExpr() = len
27+
)
28+
}
29+
2130
/**
2231
* Holds if the index expression of `aa` is less than or equal to the array length plus `k`.
2332
*/
@@ -27,12 +36,8 @@ predicate boundedArrayAccess(ArrayAccess aa, int k) {
2736
aa.getArray() = arr.getAUse() and
2837
bounded(index, b, delta, true, _)
2938
|
30-
exists(FieldAccess len |
31-
len.getField() instanceof ArrayLengthField and
32-
len.getQualifier() = arr.getAUse() and
33-
b.getExpr() = len and
34-
k = delta
35-
)
39+
ssaArrayLengthBound(arr, b) and
40+
k = delta
3641
or
3742
exists(ArrayCreationExpr arraycreation | arraycreation = getArrayDef(arr) |
3843
k = delta and

0 commit comments

Comments
 (0)