Skip to content

Commit

Permalink
Add a test for zero-sized writes through null
Browse files Browse the repository at this point in the history
  • Loading branch information
saethlin committed Oct 9, 2024
1 parent aec09a4 commit a3606d7
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/ui/precondition-checks/zero-size-null.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Test that none of the precondition checks panic on zero-sized reads or writes through null.

//@ run-pass
//@ compile-flags: -Zmir-opt-level=0 -Copt-level=0 -Cdebug-assertions=yes

use std::ptr;

fn main() {
unsafe {
ptr::copy_nonoverlapping::<u8>(ptr::null(), ptr::null_mut(), 0);
ptr::copy_nonoverlapping::<()>(ptr::null(), ptr::null_mut(), 123);
ptr::copy::<u8>(ptr::null(), ptr::null_mut(), 0);
ptr::copy::<()>(ptr::null(), ptr::null_mut(), 123);
ptr::swap::<()>(ptr::null_mut(), ptr::null_mut());
ptr::replace::<()>(ptr::null_mut(), ());
ptr::read::<()>(ptr::null());
ptr::write::<()>(ptr::null_mut(), ());
ptr::read_volatile::<()>(ptr::null());
ptr::write_volatile::<()>(ptr::null_mut(), ());
}
}

0 comments on commit a3606d7

Please sign in to comment.