Skip to content

Commit a3606d7

Browse files
committed
Add a test for zero-sized writes through null
1 parent aec09a4 commit a3606d7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Test that none of the precondition checks panic on zero-sized reads or writes through null.
2+
3+
//@ run-pass
4+
//@ compile-flags: -Zmir-opt-level=0 -Copt-level=0 -Cdebug-assertions=yes
5+
6+
use std::ptr;
7+
8+
fn main() {
9+
unsafe {
10+
ptr::copy_nonoverlapping::<u8>(ptr::null(), ptr::null_mut(), 0);
11+
ptr::copy_nonoverlapping::<()>(ptr::null(), ptr::null_mut(), 123);
12+
ptr::copy::<u8>(ptr::null(), ptr::null_mut(), 0);
13+
ptr::copy::<()>(ptr::null(), ptr::null_mut(), 123);
14+
ptr::swap::<()>(ptr::null_mut(), ptr::null_mut());
15+
ptr::replace::<()>(ptr::null_mut(), ());
16+
ptr::read::<()>(ptr::null());
17+
ptr::write::<()>(ptr::null_mut(), ());
18+
ptr::read_volatile::<()>(ptr::null());
19+
ptr::write_volatile::<()>(ptr::null_mut(), ());
20+
}
21+
}

0 commit comments

Comments
 (0)