rust/tests/compile-fail/intrinsics/ptr_offset_0_plus_0.rs

8 lines
265 B
Rust
Raw Normal View History

2021-05-08 02:33:27 -05:00
// error-pattern: pointer arithmetic failed: 0x0 is not a valid pointer
fn main() {
let x = 0 as *mut i32;
let _x = x.wrapping_offset(8); // ok, this has no inbounds tag
let _x = unsafe { x.offset(0) }; // UB despite offset 0, NULL is never inbounds
}