Created
August 28, 2021 08:28
-
-
Save mitghi/a101d8ea6c84d6041997a893b67bc1db to your computer and use it in GitHub Desktop.
Bad Rust
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
struct A { | |
value: *mut i64, | |
} | |
impl A { | |
fn new() -> A { | |
A{value: std::ptr::null_mut()} | |
} | |
} | |
fn dostuff(val: &i64, ia: &A) { | |
unsafe { | |
let a = val as *const i64 as *mut i64; | |
let b = ia as *const A as *mut A; | |
*a = 100; | |
(*b).value = a; | |
} | |
} | |
fn main() { | |
let ia = A::new(); | |
let a = 10; | |
dostuff(&a, &ia); | |
unsafe { | |
println!("{}", *(ia.value)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment