From 2e12b220be89a9253bb43ee19cb6de755add9c5f Mon Sep 17 00:00:00 2001 From: Scott Olson Date: Sun, 20 Mar 2016 20:15:13 -0600 Subject: [PATCH] Stop unintentionally clearing source relocations when copying. --- src/memory.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/memory.rs b/src/memory.rs index e5ce009d3731..496c757beafb 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -106,25 +106,25 @@ impl Memory { } pub fn copy(&mut self, src: Pointer, dest: Pointer, size: usize) -> EvalResult<()> { - let (src_bytes, relocations) = { + let (src_bytes, mut relocations) = { let alloc = try!(self.get_mut(src.alloc_id)); try!(alloc.check_relocation_edges(src.offset, src.offset + size)); let bytes = alloc.bytes[src.offset..src.offset + size].as_mut_ptr(); - let mut relocations: Vec<(usize, AllocId)> = alloc.relocations + let relocations: Vec<(usize, AllocId)> = alloc.relocations .range(Included(&src.offset), Excluded(&(src.offset + size))) .map(|(&k, &v)| (k, v)) .collect(); - for &mut (ref mut offset, _) in &mut relocations { - alloc.relocations.remove(offset); - *offset += dest.offset; - *offset -= src.offset; - } - (bytes, relocations) }; + // Update relocation offsets for the new positions in the destination allocation. + for &mut (ref mut offset, _) in &mut relocations { + *offset += dest.offset; + *offset -= src.offset; + } + let dest_bytes = try!(self.get_bytes_mut(dest, size)).as_mut_ptr(); // TODO(tsion): Clear the destination range's existing relocations.