Fix latent crash in test_wwrite_to_fd

For whatever reason this did not crash until we made it a proper Rust
unit test.
This commit is contained in:
Johannes Altmanninger 2024-01-03 21:12:13 +01:00
parent 3e3441429a
commit 1b7d4f3b90

View File

@ -1,7 +1,7 @@
use crate::ffi_tests::add_test;
use libc::{c_void, O_CREAT, O_RDWR, O_TRUNC, SEEK_SET};
use rand::random;
use std::ffi::CString;
use std::{ffi::CString, ptr};
use crate::fallback::fish_mkstemp_cloexec;
@ -86,7 +86,11 @@ add_test!("test_wwrite_to_fd", || {
let read_amt = unsafe {
libc::read(
fd.fd(),
(&mut contents[0]) as *mut u8 as *mut c_void,
if size == 0 {
ptr::null_mut()
} else {
(&mut contents[0]) as *mut u8 as *mut c_void
},
narrow.len(),
)
};