bitvec
bitvec copied to clipboard
`copy_within` panics on empty range
Unlike it's native rust equivalent, this crates' BitSlice::copy_within currently panics if called on an empty range, with an empty range, and index 0.
For my reading, this violates it's specification which has the sole restriction:
[...] both
srcanddest .. dest + src.len()must fall within the bounds ofself
I believe it is fair to say that the range 0..0 is within the bounds of the range 0..0.
The panic occurs because BitSlice::copy_within calls BitSlice::assert_in_bounds, which then tests bounds.contains(&index), which of course fails.
I ran into this edge case in practice, it is very unexpected for the programmer and quite tedious to surround all calls to this function with if !slice.is_empty() { ... }.