1
Fork 0

test that we cannot observe the bytes representing a pointer

This commit is contained in:
Ralf Jung 2017-06-04 10:43:31 -07:00
parent 6197f4fac9
commit 1d0e622a81
2 changed files with 14 additions and 0 deletions

View file

@ -0,0 +1,7 @@
fn main() {
let x = 13;
let y = &x;
let z = &y as *const &i32 as *const usize;
let ptr_bytes = unsafe { *z }; // the actual deref is fine, because we read the entire pointer at once
let _ = ptr_bytes == 15; //~ ERROR: tried to access part of a pointer value as raw bytes
}

View file

@ -0,0 +1,7 @@
fn main() {
let x = 13;
let y = &x;
let z = &y as *const &i32 as *const u8;
// the deref fails, because we are reading only a part of the pointer
let _ = unsafe { *z }; //~ ERROR: tried to access part of a pointer value as raw bytes
}