about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-08-24 07:45:59 +0000
committerbors <bors@rust-lang.org>2014-08-24 07:45:59 +0000
commit16d538cba0cc5b5830e7c17663e985d13ece8e0c (patch)
tree294ccfb06762fd94a30f9d2f2397cae7e39e5829 /src/liballoc
parentc556ca9853961793af433b3cfe58966a68a791c5 (diff)
parentb1f7d3aaa021d626b4083ddaa706b26f3521d343 (diff)
downloadrust-16d538cba0cc5b5830e7c17663e985d13ece8e0c.tar.gz
rust-16d538cba0cc5b5830e7c17663e985d13ece8e0c.zip
auto merge of #16706 : pnkfelix/rust/fsk-fix-nojem-realloc, r=thestinger
Copy only up to `min(new_size, old_size)` when doing reallocate.

This was a bug when running with jemalloc disabled.

Fix #16687
Diffstat (limited to 'src/liballoc')
-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;
     }