test that we cannot observe the bytes representing a pointer
This commit is contained in:
parent
6197f4fac9
commit
1d0e622a81
2 changed files with 14 additions and 0 deletions
7
tests/compile-fail/pointer_byte_read_1.rs
Normal file
7
tests/compile-fail/pointer_byte_read_1.rs
Normal 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
|
||||
}
|
7
tests/compile-fail/pointer_byte_read_2.rs
Normal file
7
tests/compile-fail/pointer_byte_read_2.rs
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue