From a68a1e67f414bcbe9f8c4bb1187bef2dacd79764 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Fri, 18 Dec 2020 11:40:27 +0100 Subject: [PATCH] feat(c-api) Transmute boxed vecs to `Vec>>` when deleting. It's a safer way to handle partially uninitialized boxed vector, since it protects against based deletion for every item. --- lib/c-api/src/wasm_c_api/macros.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/c-api/src/wasm_c_api/macros.rs b/lib/c-api/src/wasm_c_api/macros.rs index 0feab8cd33a..8702becdb3b 100644 --- a/lib/c-api/src/wasm_c_api/macros.rs +++ b/lib/c-api/src/wasm_c_api/macros.rs @@ -345,13 +345,7 @@ See the [`wasm_" $name "_vec_t`] type to get an example."] if let Some(vec) = ptr { if !vec.data.is_null() { let data: Vec<*mut []> = Vec::from_raw_parts(vec.data, vec.size, vec.size); - - // If the vector has been initialized (we check - // only the first item), we can transmute items to - // `Box`es. - if vec.size > 0 && !data[0].is_null() { - let _data: Vec]>> = ::std::mem::transmute(data); - } + let _data: Vec]>>> = ::std::mem::transmute(data); vec.data = ::std::ptr::null_mut(); vec.size = 0;