From abe786212c7ed242f193e930586cd07423e70e3f Mon Sep 17 00:00:00 2001 From: Martijn Swaagman Date: Tue, 25 Jan 2022 14:03:03 +0100 Subject: [PATCH 1/2] chore: allow unsafe code to deal with uninitialized data Signed-off-by: Martijn Swaagman --- src/allocator.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/allocator.rs b/src/allocator.rs index c7e1199c..27960828 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -16,13 +16,15 @@ #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; +use std::mem::MaybeUninit; + #[cfg_attr( all(target_arch = "wasm32", target_os = "unknown"), export_name = "malloc" )] #[no_mangle] pub extern "C" fn proxy_on_memory_allocate(size: usize) -> *mut u8 { - let mut vec: Vec = Vec::with_capacity(size); + let mut vec: Vec> = Vec::with_capacity(size); unsafe { vec.set_len(size); } From b692cfcc5ec3e96d6077e43e6da173a233fdadc3 Mon Sep 17 00:00:00 2001 From: Martijn Swaagman Date: Mon, 31 Jan 2022 11:44:53 +0100 Subject: [PATCH 2/2] fix: hoist use above global allocators Signed-off-by: Martijn Swaagman --- src/allocator.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 27960828..e84202b6 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::mem::MaybeUninit; + #[cfg(feature = "wee-alloc")] #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; -use std::mem::MaybeUninit; - #[cfg_attr( all(target_arch = "wasm32", target_os = "unknown"), export_name = "malloc"