Skip to content

Commit 8acfafe

Browse files
committed
test for zero-sized write_bytes to NULL
1 parent eb3be2f commit 8acfafe

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

tests/compile-fail/copy_null.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//error-pattern: invalid use of NULL pointer
21
#![feature(intrinsics)]
32

43
// Directly call intrinsic to avoid debug assertions in libstd
@@ -10,5 +9,5 @@ fn main() {
109
let mut data = [0u16; 4];
1110
let ptr = &mut data[0] as *mut u16;
1211
// Even copying 0 elements from NULL should error.
13-
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); }
12+
unsafe { copy_nonoverlapping(std::ptr::null(), ptr, 0); } //~ ERROR: invalid use of NULL pointer
1413
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#![feature(intrinsics)]
2+
3+
// Directly call intrinsic to avoid debug assertions in libstd
4+
extern "rust-intrinsic" {
5+
fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
6+
}
7+
8+
fn main() {
9+
unsafe { write_bytes::<u8>(std::ptr::null_mut(), 0, 0) }; //~ ERROR invalid use of NULL pointer
10+
}

0 commit comments

Comments
 (0)