From f21463d5f4f695332c7db27cd07e6200fd258075 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 29 Jul 2023 14:15:02 +0200 Subject: [PATCH] handle empty ranges in BitSlice::copy_within resolves #236 --- src/slice/api.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/slice/api.rs b/src/slice/api.rs index 6ac0de00..00208967 100644 --- a/src/slice/api.rs +++ b/src/slice/api.rs @@ -2229,6 +2229,12 @@ where where R: RangeExt { 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);