From abbc56a4ca7b634f5aecbdcbb840ef7d432a8dac Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 21 Jan 2026 01:18:12 +0000 Subject: [PATCH] ASpace should allow spaces with size 1 There was a test that explicitly rejected this, but because ASpace is exclusive it's actually fine for `start == end`. Adjust the test to use such a one-wide address space instead; it worked fine the whole time. --- lib/propolis/src/util/aspace.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/propolis/src/util/aspace.rs b/lib/propolis/src/util/aspace.rs index ca41a0a19..6f7b32970 100644 --- a/lib/propolis/src/util/aspace.rs +++ b/lib/propolis/src/util/aspace.rs @@ -49,9 +49,9 @@ impl ASpace { /// /// # Panics /// - /// - Panics if start >= end. + /// - Panics if start > end. pub const fn new(start: usize, end: usize) -> ASpace { - assert!(start < end); + assert!(start <= end); Self { start, end, map: BTreeMap::new() } } @@ -284,9 +284,13 @@ mod test { use super::*; #[test] - #[should_panic] - fn create_zero_size() { - let _s: ASpace = ASpace::new(0, 0); + fn create_one_elem() { + let mut s: ASpace = ASpace::new(0, 0); + s.register(0, 1, 0xaa) + .expect("can register an element in one-elem ASpace"); + assert_eq!(s.register(0, 2, 0x11), Err(Error::OutOfRange)); + assert_eq!(s.register(1, 2, 0x22), Err(Error::OutOfRange)); + assert_eq!(s.region_at(0), Ok((0, 1, &0xaa))); } #[test] fn create_max() {