Created
October 2, 2023 02:58
-
-
Save RajeshRk18/24b2f273ea689786c3bb5a19990c6166 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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