Skip to content

Instantly share code, notes, and snippets.

@berkus
Forked from rust-play/playground.rs
Last active April 16, 2019 16:34
Show Gist options
  • Save berkus/ef42431e6c3eab6eb00689dbdae1ae97 to your computer and use it in GitHub Desktop.
Save berkus/ef42431e6c3eab6eb00689dbdae1ae97 to your computer and use it in GitHub Desktop.
Transmute UB and `as` UB
#![allow(mutable_transmutes)]
use std::mem::transmute;
fn main() {
let a: Vec<u64> = Vec::new();
let r = &a;
let r: &mut Vec<u64> = unsafe { transmute(r) };
r.push(1488);
println!("{:?}", a);
let x = &666;
let y: *mut i32 = x as *const _ as *mut i32;
unsafe { *y = 5 };
println!("{:?}", x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment