Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ptr_offset_from OOB test, and update test errors #2014

Merged
merged 2 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
89adcc636f94d34a6fc90fa117e28ddf6be7b983
2c6a29af35a81e20f8af4c32bf1b55c59b89eccd
2 changes: 1 addition & 1 deletion tests/compile-fail/intrinsics/copy_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ fn main() {
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
}
2 changes: 1 addition & 1 deletion tests/compile-fail/intrinsics/ptr_offset_0_plus_0.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 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;
Expand Down
11 changes: 11 additions & 0 deletions tests/compile-fail/intrinsics/ptr_offset_from_oob.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![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
}
2 changes: 1 addition & 1 deletion tests/compile-fail/intrinsics/write_bytes_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ extern "rust-intrinsic" {
}

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
}
2 changes: 1 addition & 1 deletion tests/compile-fail/null_pointer_deref_zst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

#[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);
}
2 changes: 1 addition & 1 deletion tests/compile-fail/null_pointer_write_zst.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 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() {
Expand Down