bits-and-blooms/bitset

BitSet.Clone can be faulty under certain boundary conditions

Closed this issue · 2 comments

IMHO BitSet.Clone() can be faulty:

// Clone this BitSet
func (b *BitSet) Clone() *BitSet {
  c := New(b.length)
  if b.set != nil { // Clone should not modify current object
    copy(c.set, b.set)
  }
  return c
}

If b already requires a lot of memory, bitset.New(b.length) tries to allocate the same amount of memory again and can fail silently, because the panic is silently recovered with an empty slice.

The subsequent copy(c.set, b.set) then copies 0 items and an empty BitSet c is returned.

edited: similar problems for BitSet.Complement() and BitSet.Intersection()

We need to document the issue, see #182

Closing. If you prefer to have a panic, then new functions could be added.

(We want to avoid changing the existing behaviour of our public API.)