Skip to content

Commit

Permalink
handle empty ranges in BitSlice::copy_within
Browse files Browse the repository at this point in the history
resolves #236
  • Loading branch information
cmrschwarz committed Jul 29, 2023
1 parent 5fb8550 commit f21463d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/slice/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,12 @@ where
where R: RangeExt<usize> {
let len = self.len();
let src = src.normalize(0, len);
// prevent the asserts below from failing for empty ranges
if src.start == src.end {
assert!(src.start <= len, "range start index {} is out of bounds for bit-slice of length {}", src.start, len);
assert!(dest <= len, "index {} is out of bounds for bit-slice of length {}", dest, len);
return;
}
self.assert_in_bounds(src.start, 0 .. len);
self.assert_in_bounds(src.end, 0 ..= len);
self.assert_in_bounds(dest, 0 .. len);
Expand Down

0 comments on commit f21463d

Please sign in to comment.