diff --git a/src/lib.rs b/src/lib.rs index 522507c..64b81c2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ pub use segfault::segfault; pub use transmute::transmute; pub use use_after_free::use_after_free; -pub use references::{null, null_mut}; +pub use references::{not_alloc, null, null_mut}; /// Construct a [`String`] from a pointer, capacity and length, in a completely safe manner. /// diff --git a/src/references.rs b/src/references.rs index b1838f0..f15446e 100644 --- a/src/references.rs +++ b/src/references.rs @@ -11,7 +11,9 @@ pub fn null_mut<'a, T: 'static>() -> &'a mut T { } /// Not allocate an object. The returned reference is always invalid. -/// This is equivalent to [`crate::null_mut()`]. +/// +/// **Note:** It turns out that `null` is a valid memory address in WASM. +/// So here we use the maximum address instead. pub fn not_alloc<'a, T: 'static>() -> &'a mut T { - null_mut() + crate::transmute(usize::MAX) } diff --git a/src/segfault.rs b/src/segfault.rs index 53660e7..f4fd63d 100644 --- a/src/segfault.rs +++ b/src/segfault.rs @@ -12,7 +12,7 @@ pub fn segfault() -> ! { // If null doesn't work, try max. Surely that'll stop it. // Confirmed to be effective on WASM. - let max = crate::transmute::(usize::MAX); + let max = crate::not_alloc::(); *max = 69; unreachable!("Sorry, your platform is too strong.")