shrink_to_fit method corrupts an empty bitset
alexeiakimov opened this issue · comments
alexeiakimov commented
Bug in BitSet::shrink_to_fit method
Crate version: 0.5.2
Description: BitSet::shrink_to_fit(...) method being applied to a newly created bitset corrupts the internals state of the bit set. The following test demonstrates the problem:
#[test]
fn shrink_new_bit_set() {
let mut set = BitSet::new();
set.shrink_to_fit();
set.contains(1);
}
The last line panics with message "index out of bounds". The cause is that in lib.rs, line 389 the trunc_len
is set to 1 if there are no blocks, after truncation the vector of blocks is still empty but the number of bits is set to the size of the single block.
Aria Beingessner commented
wow, yep! good catch!
Aria Beingessner commented
fixed in 0.5.3, which is now published