Skip to content

Instantly share code, notes, and snippets.

@RajeshRk18
Created October 2, 2023 02:58
Show Gist options
  • Save RajeshRk18/24b2f273ea689786c3bb5a19990c6166 to your computer and use it in GitHub Desktop.
Save RajeshRk18/24b2f273ea689786c3bb5a19990c6166 to your computer and use it in GitHub Desktop.
use cheetah::Scalar;
let (mut a, ptr) = {
let b = Scalar::new([12, 34, 56, 78]);
println!("Creation Address: {:?}", b.0.as_ptr());
(b, b.0.as_ptr())
};
println!("Value before dropping: {:?}", a.0);
let addr_a = a.0.as_ptr();
let zero: [u64; 4] = [0, 0, 0, 0];
println!("Returned Address: {:?}", a.0.as_ptr());
a.zeroize();
let val_at_returned_memory = unsafe {
core::slice::from_raw_parts(addr_a, 4)
};
println!("Value at Returned Address: {:?}", val_at_returned_memory); // Zeroed
let val_at_dropped_memory = unsafe {
core::slice::from_raw_parts(ptr, 4)
};
println!("Value at Creation Address: {:?}", val_at_dropped_memory); // value still in memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment