Skip to content

Commit

Permalink
Potential fix
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Oct 30, 2024
1 parent 3898ac6 commit eccdff8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion libwasmvm/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u8>(), 0, 0)
} else {
(data.as_mut_ptr(), data.len(), data.capacity())
}
};
Self {
is_none: false,
Expand Down

0 comments on commit eccdff8

Please sign in to comment.