mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Java: Account for additional constants in ArrayIndexOutOfBounds query.
This commit is contained in:
@@ -204,4 +204,11 @@ public class A {
|
||||
A.arr1[RandomUtils.nextInt(0, arr1.length + 1)] + // BAD: random int may be out of range
|
||||
A.arr1[RandomUtils.nextInt(0, arr1.length)]; // GOOD: random int must be in range
|
||||
}
|
||||
|
||||
int m17() {
|
||||
return this.arr2[(new Random()).nextInt(arr2.length + 1)] + // BAD: random int may be out of range
|
||||
this.arr2[(new Random()).nextInt(arr2.length)] + // GOOD: random int must be in range
|
||||
this.arr2[RandomUtils.nextInt(0, arr2.length + 1)] + // BAD: random int may be out of range
|
||||
this.arr2[RandomUtils.nextInt(0, arr2.length)]; // GOOD: random int must be in range
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,3 +14,5 @@
|
||||
| A.java:195:9:195:13 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
|
||||
| A.java:202:12:202:58 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
|
||||
| A.java:204:7:204:53 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
|
||||
| A.java:209:12:209:61 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
|
||||
| A.java:211:7:211:56 | ...[...] | This array access might be out of bounds, as the index might be equal to the array length. |
|
||||
|
||||
Reference in New Issue
Block a user