Skip to content

copy_within panics on empty range #236

@cmrschwarz

Description

@cmrschwarz

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions