From 089e7e127e2d76483df0a0b2059fb97cf4b2f5e8 Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 10 Jun 2019 15:21:44 -0500 Subject: [PATCH] handle insertions correctly The "Update" case for Slice containers is broken, and can insert a container without inserting a key. Fix this by using the existing insert/add logic. --- roaring/containers_slice.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/roaring/containers_slice.go b/roaring/containers_slice.go index cbff4f179..df44b4ff1 100644 --- a/roaring/containers_slice.go +++ b/roaring/containers_slice.go @@ -196,9 +196,7 @@ func (sc *sliceContainers) Update(key uint64, fn func(*Container, bool) (*Contai // don't expand the slice just to add a nil container, we // could return that anyway if write && nc != nil { - sc.containers = append(sc.containers, nil) - copy(sc.containers[i+1:], sc.containers[i:]) - sc.containers[i] = nc + sc.insertAt(key, nc, -i-1) } } }