nextSetBit should check if the underlaying array contains the current word (#62805) (#62812)

This is a recent addition and it is missing a check as the underlaying array can be smaller that the numBits capacity.
This commit is contained in:
Ignacio Vera 2020-09-23 11:17:26 +02:00 committed by GitHub
parent 862fab06d3
commit 81645ec2cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 0 deletions

View File

@ -66,6 +66,9 @@ public final class BitArray implements Releasable {
public long nextSetBit(long index) {
long wordNum = wordNum(index);
if (wordNum >= bits.size()) {
return Long.MAX_VALUE;
}
long word = bits.get(wordNum) >> index; // skip all the bits to the right of index
if (word!=0) {