Skip to content

Commit b1f7d3a

Browse files
committed
Copy only up to min(new_size, old_size) when doing reallocate.
Fix rust-lang#16687
1 parent b0b4851 commit b1f7d3a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/liballoc/heap.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ mod imp {
208208

209209
#[cfg(not(jemalloc), unix)]
210210
mod imp {
211+
use core::cmp;
211212
use core::mem;
212213
use core::ptr;
213214
use libc;
@@ -248,7 +249,7 @@ mod imp {
248249
pub unsafe fn reallocate(ptr: *mut u8, size: uint, align: uint,
249250
old_size: uint) -> *mut u8 {
250251
let new_ptr = allocate(size, align);
251-
ptr::copy_memory(new_ptr, ptr as *const u8, old_size);
252+
ptr::copy_memory(new_ptr, ptr as *const u8, cmp::min(size, old_size));
252253
deallocate(ptr, old_size, align);
253254
return new_ptr;
254255
}

0 commit comments

Comments
 (0)