Skip to content

Commit c58298c

Browse files
committed
Auto merge of #2014 - RalfJung:ptr-offset-from, r=RalfJung
add ptr_offset_from OOB test, and update test errors The Miri side of rust-lang/rust#94827.
2 parents a35877b + 21ff2f9 commit c58298c

7 files changed

+17
-6
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
89adcc636f94d34a6fc90fa117e28ddf6be7b983
1+
2c6a29af35a81e20f8af4c32bf1b55c59b89eccd

tests/compile-fail/intrinsics/copy_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ fn main() {
99
let mut data = [0u16; 4];
1010
let ptr = &mut data[0] as *mut u16;
1111
// Even copying 0 elements from NULL should error.
12-
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: memory access failed: 0x0 is not a valid pointer
12+
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: memory access failed: null pointer is not a valid pointer
1313
}

tests/compile-fail/intrinsics/ptr_offset_0_plus_0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// error-pattern: pointer arithmetic failed: 0x0 is not a valid pointer
1+
// error-pattern: pointer arithmetic failed: null pointer is not a valid pointer
22

33
fn main() {
44
let x = 0 as *mut i32;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(core_intrinsics)]
2+
3+
use std::intrinsics::ptr_offset_from;
4+
5+
fn main() {
6+
let start_ptr = &4 as *const _ as *const u8;
7+
let length = 10;
8+
let end_ptr = start_ptr.wrapping_add(length);
9+
// Even if the offset is 0, a dangling OOB pointer is not allowed.
10+
unsafe { ptr_offset_from(end_ptr, end_ptr) }; //~ERROR pointer at offset 10 is out-of-bounds
11+
}

tests/compile-fail/intrinsics/write_bytes_null.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ extern "rust-intrinsic" {
66
}
77

88
fn main() {
9-
unsafe { write_bytes::<u8>(std::ptr::null_mut(), 0, 0) }; //~ ERROR memory access failed: 0x0 is not a valid pointer
9+
unsafe { write_bytes::<u8>(std::ptr::null_mut(), 0, 0) }; //~ ERROR memory access failed: null pointer is not a valid pointer
1010
}

tests/compile-fail/null_pointer_deref_zst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
#[allow(deref_nullptr)]
55
fn main() {
6-
let x: () = unsafe { *std::ptr::null() }; //~ ERROR dereferencing pointer failed: 0x0 is not a valid pointer
6+
let x: () = unsafe { *std::ptr::null() }; //~ ERROR dereferencing pointer failed: null pointer is not a valid pointer
77
panic!("this should never print: {:?}", x);
88
}

tests/compile-fail/null_pointer_write_zst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Some optimizations remove ZST accesses, thus masking this UB.
22
// compile-flags: -Zmir-opt-level=0
3-
// error-pattern: memory access failed: 0x0 is not a valid pointer
3+
// error-pattern: memory access failed: null pointer is not a valid pointer
44

55
#[allow(deref_nullptr)]
66
fn main() {

0 commit comments

Comments
 (0)