From ee95aec91cffb3251fbde83d2fce44f2081f9823 Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Tue, 26 Apr 2016 14:41:37 -0500 Subject: [PATCH] check for iterator overflow --- roaring/roaring.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index f6c3cf742..b425a3690 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -366,12 +366,16 @@ func (itr *Iterator) Next() uint64 { itr.j++ return itr.peek() } - // Move to the next possible index in the bitmap container. itr.j++ // Find first non-zero bit in current bitmap, if possible. hb := int(itr.j / 64) + + if hb >= len(c.bitmap) { + itr.i, itr.j = itr.i+1, -1 + continue + } lb := c.bitmap[hb] >> (uint(itr.j) % 64) if lb != 0 { itr.j = int(itr.j) + trailingZeroN(lb)