]>
Commit | Line | Data |
---|---|---|
ea8adc8c XL |
1 | #![feature(core_intrinsics)] |
2 | ||
3 | use std::mem; | |
4 | ||
5 | fn main() { | |
6 | let x: Option<Box<[u8]>> = unsafe { | |
7 | let z = std::intrinsics::add_with_overflow(0usize, 0usize); | |
8 | std::mem::transmute::<(usize, bool), Option<Box<[u8]>>>(z) | |
9 | }; | |
10 | let y = &x; | |
11 | // Now read this bytewise. There should be (ptr_size+1) def bytes followed by (ptr_size-1) undef bytes (the padding after the bool) in there. | |
12 | let z : *const u8 = y as *const _ as *const _; | |
13 | let first_undef = mem::size_of::<usize>() as isize + 1; | |
14 | for i in 0..first_undef { | |
15 | let byte = unsafe { *z.offset(i) }; | |
16 | assert_eq!(byte, 0); | |
17 | } | |
18 | let v = unsafe { *z.offset(first_undef) }; | |
19 | if v == 0 {} //~ ERROR attempted to read undefined bytes | |
20 | } |