BitSet.Clone can be faulty under certain boundary conditions
Closed this issue · 2 comments
gaissmai commented
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()
lemire commented
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.)