diff --git a/lib/c-api/src/wasm_c_api/macros.rs b/lib/c-api/src/wasm_c_api/macros.rs index 49989acd7..0feab8cd3 100644 --- a/lib/c-api/src/wasm_c_api/macros.rs +++ b/lib/c-api/src/wasm_c_api/macros.rs @@ -341,21 +341,21 @@ int main() { See the [`wasm_" $name "_vec_t`] type to get an example."] #[no_mangle] - pub unsafe extern "C" fn [](ptr: *mut []) { - let vec = &mut *ptr; + pub unsafe extern "C" fn [](ptr: Option<&mut []>) { + 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 !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); + } - // 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); + vec.data = ::std::ptr::null_mut(); + vec.size = 0; } - - vec.data = ::std::ptr::null_mut(); - vec.size = 0; } } }