diff --git a/libwasmvm/src/memory.rs b/libwasmvm/src/memory.rs index 667aaa595..bf8d874a2 100644 --- a/libwasmvm/src/memory.rs +++ b/libwasmvm/src/memory.rs @@ -220,7 +220,14 @@ impl UnmanagedVector { // Can be replaced with Vec::into_raw_parts when stable // https://doc.rust-lang.org/std/vec/struct.Vec.html#method.into_raw_parts let mut data = mem::ManuallyDrop::new(data); - (data.as_mut_ptr(), data.len(), data.capacity()) + if data.capacity() == 0 { + // we need to explicitly use a null pointer here, since `as_mut_ptr` can + // return arbitrary addresses (e.g. 0x01) on an empty Vec, + // which trips up Go's pointer checks + (std::ptr::null_mut::(), 0, 0) + } else { + (data.as_mut_ptr(), data.len(), data.capacity()) + } }; Self { is_none: false,