Don't pass 0-length mallocs to system allocator

Part of the unsafe contract!
This commit is contained in:
Alex Crichton 2018-10-28 08:51:47 -07:00
parent 1fa407d2f9
commit 78f425744f

View File

@ -827,9 +827,13 @@ pub mod __rt {
let align = mem::align_of::<usize>();
if let Ok(layout) = Layout::from_size_align(size, align) {
unsafe {
let ptr = alloc(layout);
if !ptr.is_null() {
return ptr
if layout.size() > 0 {
let ptr = alloc(layout);
if !ptr.is_null() {
return ptr
}
} else {
return align as *mut u8
}
}
}