From 1b7d4f3b90f3fd6a280534e39a42d9b446b13404 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 3 Jan 2024 21:12:13 +0100 Subject: [PATCH] Fix latent crash in test_wwrite_to_fd For whatever reason this did not crash until we made it a proper Rust unit test. --- fish-rust/src/wutil/tests.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fish-rust/src/wutil/tests.rs b/fish-rust/src/wutil/tests.rs index 2813e9ea5..bf76e25ff 100644 --- a/fish-rust/src/wutil/tests.rs +++ b/fish-rust/src/wutil/tests.rs @@ -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 @@ fn test_wdirname_wbasename() { 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(), ) };