rust/tests/compile-fail/ptr_wrapping_offset_int_plus_ptr.rs

9 lines
265 B
Rust
Raw Normal View History

// error-pattern: pointer value as raw bytes
fn main() {
2018-10-07 03:35:34 -05:00
let ptr = Box::into_raw(Box::new(0u32));
// Can't start with an integer pointer and get to something usable
let ptr = (1 as *mut u8).wrapping_offset(ptr as isize);
let _ = unsafe { *ptr };
}