diff options
| author | bors <bors@rust-lang.org> | 2017-11-25 06:16:19 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-11-25 06:16:19 +0000 |
| commit | 59bf09d4d473c803609d3ad925a0ebf13bdbb0ab (patch) | |
| tree | 8357c4f6e256ae8b198de5f1bd729118d6dd1f74 /src/liballoc_system | |
| parent | ca8ef2629363ead527452d15ab628633c8fd2d52 (diff) | |
| parent | 43e32b53462e139c560672102724e8a8c859dbf7 (diff) | |
| download | rust-59bf09d4d473c803609d3ad925a0ebf13bdbb0ab.tar.gz rust-59bf09d4d473c803609d3ad925a0ebf13bdbb0ab.zip | |
Auto merge of #46117 - SimonSapin:min-align, r=alexcrichton
allocators: don’t assume MIN_ALIGN for small sizes See individual commit messages.
Diffstat (limited to 'src/liballoc_system')
| -rw-r--r-- | src/liballoc_system/lib.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 05cacf6e881..27259cc31a5 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -25,8 +25,7 @@ #![rustc_alloc_kind = "lib"] // The minimum alignment guaranteed by the architecture. This value is used to -// add fast paths for low alignment values. In practice, the alignment is a -// constant at the call site and the branch will be optimized out. +// add fast paths for low alignment values. #[cfg(all(any(target_arch = "x86", target_arch = "arm", target_arch = "mips", @@ -132,7 +131,7 @@ mod platform { unsafe impl<'a> Alloc for &'a System { #[inline] unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> { - let ptr = if layout.align() <= MIN_ALIGN { + let ptr = if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { libc::malloc(layout.size()) as *mut u8 } else { aligned_malloc(&layout) @@ -148,7 +147,7 @@ mod platform { unsafe fn alloc_zeroed(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> { - if layout.align() <= MIN_ALIGN { + if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() { let ptr = libc::calloc(layout.size(), 1) as *mut u8; if !ptr.is_null() { Ok(ptr) @@ -180,7 +179,7 @@ mod platform { }) } - if new_layout.align() <= MIN_ALIGN { + if new_layout.align() <= MIN_ALIGN && new_layout.align() <= new_layout.size(){ let ptr = libc::realloc(ptr as *mut libc::c_void, new_layout.size()); if !ptr.is_null() { Ok(ptr as *mut u8) |
