mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 05:26:23 +03:00
add a scary test case
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
fn main() {
|
||||
// If we are careful, we can exploit data layout...
|
||||
let raw = unsafe {
|
||||
std::mem::transmute::<&[u8], [usize; 2]>(&[42])
|
||||
};
|
||||
let ptr = raw[0] + raw[1];
|
||||
let ptr = ptr as *const u8;
|
||||
// The pointer is one-past-the end, but we decrement it into bounds before using it
|
||||
assert_eq!(unsafe { *ptr.offset(-1) }, 42);
|
||||
}
|
||||
Reference in New Issue
Block a user