BitBuffer icon indicating copy to clipboard operation
BitBuffer copied to clipboard

[BUG] BitBuffer .put and .get methods with arrays have inverted condition on for loop

Open henry701 opened this issue 4 years ago • 0 comments

As an example, there is the following code on BitBuffer abstract class convenience method for putting boolean arrays:

public BitBuffer put(boolean[] array) {
    put(array, 0, array.length);
    return this;
}

Which int turn invokes method:

public BitBuffer put(boolean[] array, int offset, int limit) {
    for(; offset > limit; ++offset) {
        put(array[offset]);
    }
    return this;
}

However when invoked the method always skip the for, because the condition is inverted: offset (initial 0) is always <= limit when entering the method!

This is repeated on all instances of such methods, just swapping offset > limit for offset < limit should do the trick!

henry701 avatar Jun 09 '21 21:06 henry701