diff options
| author | Ben Kimock <kimockb@gmail.com> | 2024-10-09 18:46:06 -0400 |
|---|---|---|
| committer | Ben Kimock <kimockb@gmail.com> | 2024-10-09 19:34:27 -0400 |
| commit | a3606d7ee3dd9d910578a81b2992e61521b1ce21 (patch) | |
| tree | 88b51ee4a8dc284ffe237ac1857dc5a6bdf58c06 | |
| parent | aec09a43efed613ed12e32cef5d1bd94750e04eb (diff) | |
| download | rust-a3606d7ee3dd9d910578a81b2992e61521b1ce21.tar.gz rust-a3606d7ee3dd9d910578a81b2992e61521b1ce21.zip | |
Add a test for zero-sized writes through null
| -rw-r--r-- | tests/ui/precondition-checks/zero-size-null.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/ui/precondition-checks/zero-size-null.rs b/tests/ui/precondition-checks/zero-size-null.rs new file mode 100644 index 00000000000..43a81175f94 --- /dev/null +++ b/tests/ui/precondition-checks/zero-size-null.rs @@ -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(), ()); + } +} |
