From 6be14eab15242f503e56bf023237651bea43861d Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Thu, 7 Apr 2016 03:07:57 -0600 Subject: [PATCH] Handle missing allocations in Memory::dump. --- src/memory.rs | 9 ++++++++- test/pointers.rs | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/memory.rs b/src/memory.rs index 661f4567264..105bcf68849 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -176,11 +176,18 @@ pub fn dump(&self, id: AllocId) { while let Some(id) = allocs_to_print.pop_front() { allocs_seen.insert(id.0); - let alloc = self.get(id).unwrap(); let prefix = format!("Alloc {:<5} ", format!("{}:", id.0)); print!("{}", prefix); let mut relocations = vec![]; + let alloc = match self.alloc_map.get(&id.0) { + Some(a) => a, + None => { + println!("(deallocated)"); + continue; + } + }; + for i in 0..alloc.bytes.len() { if let Some(&target_id) = alloc.relocations.get(&i) { if !allocs_seen.contains(&target_id.0) { diff --git a/test/pointers.rs b/test/pointers.rs index 494adf243ac..9e7e217ec5c 100644 --- a/test/pointers.rs +++ b/test/pointers.rs @@ -51,3 +51,9 @@ fn match_ref_mut() -> i8 { } t.0 } + +#[miri_run] +fn dangling_pointer() -> *const i32 { + let b = Box::new(42); + &*b as *const i32 +} -- 2.44.0