From 999c4fd767ad0aa6c8e5cafbf2c6bc1d1b617d6e Mon Sep 17 00:00:00 2001 From: mohanson Date: Tue, 19 Mar 2024 11:13:46 +0800 Subject: [PATCH] The get_page_indices function requires that length cannot be 0 --- 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 27bf471a..bb0caae5 100644 --- a/src/snapshot2.rs +++ b/src/snapshot2.rs @@ -267,6 +267,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 99cda4c2..3d2e026b 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); }