about summary refs log tree commit diff
path: root/src/liballoc/heap.rs
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2014-08-23 17:29:48 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2014-08-23 19:23:02 +0200
commitb1f7d3aaa021d626b4083ddaa706b26f3521d343 (patch)
tree7a8e662e23dae82445f2b214de025f56c6137f71 /src/liballoc/heap.rs
parentb0b48511dae63b2e86d002930e54cef7c0d6009e (diff)
downloadrust-b1f7d3aaa021d626b4083ddaa706b26f3521d343.tar.gz
rust-b1f7d3aaa021d626b4083ddaa706b26f3521d343.zip
Copy only up to `min(new_size, old_size)` when doing reallocate.
Fix #16687
Diffstat (limited to 'src/liballoc/heap.rs')
-rw-r--r--src/liballoc/heap.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs
index e2faa3240ed..ab686cb01d6 100644
--- a/src/liballoc/heap.rs
+++ b/src/liballoc/heap.rs
@@ -208,6 +208,7 @@ mod imp {
 
 #[cfg(not(jemalloc), unix)]
 mod imp {
+    use core::cmp;
     use core::mem;
     use core::ptr;
     use libc;
@@ -248,7 +249,7 @@ mod imp {
     pub unsafe fn reallocate(ptr: *mut u8, size: uint, align: uint,
                              old_size: uint) -> *mut u8 {
         let new_ptr = allocate(size, align);
-        ptr::copy_memory(new_ptr, ptr as *const u8, old_size);
+        ptr::copy_memory(new_ptr, ptr as *const u8, cmp::min(size, old_size));
         deallocate(ptr, old_size, align);
         return new_ptr;
     }