add a scary test case
This commit is contained in:
parent
04b925135d
commit
bfda0a0a90
1 changed files with 10 additions and 0 deletions
10
tests/run-pass/transmute_fat.rs
Normal file
10
tests/run-pass/transmute_fat.rs
Normal file
|
|
@ -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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue