Skip to content

Commit

Permalink
Copy only up to min(new_size, old_size) when doing reallocate.
Browse files Browse the repository at this point in the history
Fix #16687
  • Loading branch information
pnkfelix committed Aug 23, 2014
1 parent b0b4851 commit b1f7d3a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/liballoc/heap.rs
Expand Up @@ -208,6 +208,7 @@ mod imp {

#[cfg(not(jemalloc), unix)]
mod imp {
use core::cmp;
use core::mem;
use core::ptr;
use libc;
Expand Down Expand Up @@ -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;
}
Expand Down

5 comments on commit b1f7d3a

@bors
Copy link
Contributor

@bors bors commented on b1f7d3a Aug 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from thestinger
at pnkfelix@b1f7d3a

@bors
Copy link
Contributor

@bors bors commented on b1f7d3a Aug 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pnkfelix/rust/fsk-fix-nojem-realloc = b1f7d3a into auto

@bors
Copy link
Contributor

@bors bors commented on b1f7d3a Aug 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pnkfelix/rust/fsk-fix-nojem-realloc = b1f7d3a merged ok, testing candidate = 16d538c

@bors
Copy link
Contributor

@bors bors commented on b1f7d3a Aug 24, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 16d538c

Please sign in to comment.