From 219a150eb8d874fabb3e1142323fee10f9633a7e Mon Sep 17 00:00:00 2001 From: Mohanson Date: Tue, 19 Mar 2024 12:20:45 +0800 Subject: [PATCH] The get_page_indices function requires that length cannot be 0 (#420) (#421) --- src/snapshot2.rs | 3 +++ tests/test_resume2.rs | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/snapshot2.rs b/src/snapshot2.rs index a01603a9..9999956c 100644 --- a/src/snapshot2.rs +++ b/src/snapshot2.rs @@ -263,6 +263,9 @@ impl> Snapshot2Context { start: u64, length: u64, ) -> Result<(), Error> { + if length == 0 { + return Ok(()); + } let page_indices = get_page_indices(start, length)?; for page in page_indices.0..=page_indices.1 { machine.memory_mut().set_flag(page, FLAG_DIRTY)?; diff --git a/tests/test_resume2.rs b/tests/test_resume2.rs index 6e435272..30f35b8a 100644 --- a/tests/test_resume2.rs +++ b/tests/test_resume2.rs @@ -649,13 +649,13 @@ pub fn test_store_bytes_twice() { } _ => unimplemented!(), } - let a = machine.full_memory().unwrap()[4096 * 2]; + let mem1 = machine.full_memory().unwrap(); let snapshot = machine.snapshot().unwrap(); let mut machine2 = MachineTy::Asm.build(data_source.clone(), VERSION2); machine2.resume(snapshot).unwrap(); machine2.set_max_cycles(u64::MAX); - let b = machine2.full_memory().unwrap()[4096 * 2]; + let mem2 = machine2.full_memory().unwrap(); - assert_eq!(a, b); + assert_eq!(mem1, mem2); }