Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy_within panics on empty range #236

Open
cmrschwarz opened this issue Jul 29, 2023 · 0 comments · May be fixed by #237
Open

copy_within panics on empty range #236

cmrschwarz opened this issue Jul 29, 2023 · 0 comments · May be fixed by #237

Comments

@cmrschwarz
Copy link

cmrschwarz commented Jul 29, 2023

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 src and dest .. dest + src.len() must fall within the bounds of self

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() { ... }.

@cmrschwarz cmrschwarz changed the title copy_within panics on empty range copy_within panics on empty range Jul 29, 2023
cmrschwarz added a commit to cmrschwarz/bitvec that referenced this issue Jul 29, 2023
cmrschwarz added a commit to cmrschwarz/bitvec that referenced this issue Jul 29, 2023
@cmrschwarz cmrschwarz linked a pull request Jul 29, 2023 that will close this issue
cmrschwarz added a commit to cmrschwarz/bitvec that referenced this issue Jul 29, 2023
cmrschwarz added a commit to cmrschwarz/bitvec that referenced this issue Jul 29, 2023
cmrschwarz added a commit to cmrschwarz/bitvec that referenced this issue Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant