rust/tests/compile-fail/ptr_offset_ptr_plus_0.rs

8 lines
295 B
Rust
Raw Normal View History

2018-10-08 11:22:52 +02:00
// error-pattern: outside bounds of allocation
fn main() {
let x = Box::into_raw(Box::new(0u32));
2019-02-16 01:43:56 +00:00
let x = x.wrapping_offset(8); // ok, this has no inbounds tag
2018-10-08 11:22:52 +02:00
let _x = unsafe { x.offset(0) }; // UB despite offset 0, the pointer is not inbounds of the only object it can point to
}