Merge pull request #988 from alexcrichton/no-zero-size

Don't pass 0-length mallocs to system allocator
This commit is contained in:
Alex Crichton 2018-10-28 12:29:03 -07:00 committed by GitHub
commit efd4dd3ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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
}
}
}