Skip to content

Commit

Permalink
Fixed bug with runtime container "index out of range". We should chec…
Browse files Browse the repository at this point in the history
…k curIndex is non-negative
  • Loading branch information
alldroll committed Aug 14, 2019
1 parent 881e88d commit a4937ad
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func testContainerIteratorPeekNext(t *testing.T, c container) {
}

func testContainerIteratorAdvance(t *testing.T, con container) {
values := []uint16{2, 15, 16, 31, 32, 33, 9999}
values := []uint16{1, 2, 15, 16, 31, 32, 33, 9999}
for _, v := range values {
con.iadd(v)
}
Expand All @@ -80,8 +80,8 @@ func testContainerIteratorAdvance(t *testing.T, con container) {
minval uint16
expected uint16
}{
{0, 2},
{1, 2},
{0, 1},
{1, 1},
{2, 2},
{3, 15},
{30, 31},
Expand Down
6 changes: 3 additions & 3 deletions roaring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ func TestIteratorPeekNext(t *testing.T) {
}

func TestIteratorAdvance(t *testing.T) {
values := []uint32{2, 15, 16, 31, 32, 33, 9999, MaxUint16}
values := []uint32{1, 2, 15, 16, 31, 32, 33, 9999, MaxUint16}
bm := New()
for n := 0; n < len(values); n++ {
bm.Add(values[n])
Expand All @@ -2207,8 +2207,8 @@ func TestIteratorAdvance(t *testing.T) {
minval uint32
expected uint32
}{
{0, 2},
{1, 2},
{0, 1},
{1, 1},
{2, 2},
{3, 15},
{30, 31},
Expand Down
5 changes: 4 additions & 1 deletion runcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,10 @@ func (ri *runIterator16) advanceIfNeeded(minval uint16) {
ri.curIndex = interval
}

ri.curPosInIndex = ri.rc.iv[ri.curIndex].length
// we should set a position to the previous container, only if the iterator doesn't point on the first container
if ri.curIndex >= 0 {
ri.curPosInIndex = ri.rc.iv[ri.curIndex].length
}
}

for ri.hasNext() && ri.peekNext() < minval {
Expand Down

0 comments on commit a4937ad

Please sign in to comment.