From 36355a5c83bf868f70965648b89b8a394648ba37 Mon Sep 17 00:00:00 2001 From: bendn Date: Sat, 9 Sep 2023 17:54:54 +0700 Subject: [PATCH] fix debug_assert and add test for repeat --- Cargo.toml | 2 +- src/lib.rs | 10 ++++++++++ src/overlay.rs | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8cd21d1..e568401 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fimg" -version = "0.3.3" +version = "0.3.4" authors = ["bend-n "] license = "MIT" edition = "2021" diff --git a/src/lib.rs b/src/lib.rs index 492bfc0..3bbe6c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -372,3 +372,13 @@ macro_rules! img { } #[cfg(test)] use img; + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn repeat() { + let x: Image<&[u8], 3> = Image::build(8, 8).buf(include_bytes!("../benches/3_8x8.imgbuf")); + unsafe { x.repeated(128, 128) }; // repeat 16 times + } +} diff --git a/src/overlay.rs b/src/overlay.rs index fbc9b17..cb11d78 100644 --- a/src/overlay.rs +++ b/src/overlay.rs @@ -131,8 +131,9 @@ impl OverlayAt> for Image<&mut [u8], 3> { let o_x = ((j + y as usize) * self.width() as usize + x as usize) * 3 ..((j + y as usize) * self.width() as usize + x as usize + ($n as usize)) * 3; - debug_assert!(o_x.end < self.buffer().len()); - debug_assert!(i_x.end < with.buffer().len()); + // <= because ".." range + debug_assert!(o_x.end <= self.buffer().len()); + debug_assert!(i_x.end <= with.buffer().len()); // SAFETY: bounds are ✅ let a = unsafe { self.buffer.get_unchecked_mut(o_x) }; // SAFETY: we are in ⬜!