Last active
October 2, 2023 02:44
-
-
Save RajeshRk18/70ebddf1060ea480cbd87db71bd89152 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 lambdaworks_math::unsigned_integer::element::UnsignedInteger; | |
fn main() { | |
let (mut a, ptr) = { | |
let b = UnsignedInteger::<4>::from_limbs([1234, 234, 567, 987]); | |
println!("Creation Address: {:?}", b.limbs.as_ptr()); | |
(b, b.limbs.as_ptr()) | |
}; | |
println!("Value before dropping: {:?}", a.limbs); | |
let addr_a = a.limbs.as_ptr(); | |
println!("Returned Address: {:?}", addr_a); | |
let zero: [u64; 4] = [0, 0, 0, 0]; | |
unsafe { | |
core::ptr::write_volatile(&mut a.limbs, zero); | |
} | |
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