let mut data = [0u16; 4];
let ptr = &mut data[0] as *mut u16;
// Even copying 0 elements from NULL should error.
- unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: memory access failed: 0x0 is not a valid pointer
+ unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: memory access failed: null pointer is not a valid pointer
}
-// error-pattern: pointer arithmetic failed: 0x0 is not a valid pointer
+// error-pattern: pointer arithmetic failed: null pointer is not a valid pointer
fn main() {
let x = 0 as *mut i32;
--- /dev/null
+#![feature(core_intrinsics)]
+
+use std::intrinsics::ptr_offset_from;
+
+fn main() {
+ let start_ptr = &4 as *const _ as *const u8;
+ let length = 10;
+ let end_ptr = start_ptr.wrapping_add(length);
+ // Even if the offset is 0, a dangling OOB pointer is not allowed.
+ unsafe { ptr_offset_from(end_ptr, end_ptr) }; //~ERROR pointer at offset 10 is out-of-bounds
+}
}
fn main() {
- unsafe { write_bytes::<u8>(std::ptr::null_mut(), 0, 0) }; //~ ERROR memory access failed: 0x0 is not a valid pointer
+ unsafe { write_bytes::<u8>(std::ptr::null_mut(), 0, 0) }; //~ ERROR memory access failed: null pointer is not a valid pointer
}
#[allow(deref_nullptr)]
fn main() {
- let x: () = unsafe { *std::ptr::null() }; //~ ERROR dereferencing pointer failed: 0x0 is not a valid pointer
+ let x: () = unsafe { *std::ptr::null() }; //~ ERROR dereferencing pointer failed: null pointer is not a valid pointer
panic!("this should never print: {:?}", x);
}
// Some optimizations remove ZST accesses, thus masking this UB.
// compile-flags: -Zmir-opt-level=0
-// error-pattern: memory access failed: 0x0 is not a valid pointer
+// error-pattern: memory access failed: null pointer is not a valid pointer
#[allow(deref_nullptr)]
fn main() {