rust/tests/compile-fail/ptr_eq_out_of_bounds_null.rs
2018-09-17 10:02:31 +02:00

7 lines
290 B
Rust

fn main() {
let b = Box::new(0);
let x = (&*b as *const i32).wrapping_sub(0x800); // out-of-bounds
// We cannot compare this with NULL. After all, this *could* be NULL (with the right base address).
assert!(x != std::ptr::null()); //~ ERROR invalid arithmetic on pointers
}