mirror of
https://github.com/rustwasm/wasm-bindgen.git
synced 2024-12-28 04:22:38 +03:00
Don't pass 0-length mallocs to system allocator
Part of the unsafe contract!
This commit is contained in:
parent
1fa407d2f9
commit
78f425744f
10
src/lib.rs
10
src/lib.rs
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user