From e274ff41d0338788972252a0d240752d676fb04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E9=80=B8?= Date: Mon, 19 May 2025 20:52:55 +0800 Subject: [PATCH] Use uninit instead of zeroed (src/input_common.rs) (cherry picked from commit 7c2c7f5874e077834e5c9c5866b089dcc480af1e) --- src/input_common.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/input_common.rs b/src/input_common.rs index 1be6aafb0..ddfe17a3f 100644 --- a/src/input_common.rs +++ b/src/input_common.rs @@ -21,6 +21,7 @@ use crate::wutil::encoding::{mbrtowc, mbstate_t, zero_mbstate}; use crate::wutil::fish_wcstol; use std::collections::VecDeque; +use std::mem::MaybeUninit; use std::os::fd::RawFd; use std::os::unix::ffi::OsStrExt; use std::ptr; @@ -1316,8 +1317,8 @@ fn readch_timed(&mut self, wait_time_ms: usize) -> Option { // We are not prepared to handle a signal immediately; we only want to know if we get input on // our fd before the timeout. Use pselect to block all signals; we will handle signals // before the next call to readch(). - let mut sigs: libc::sigset_t = unsafe { std::mem::zeroed() }; - unsafe { libc::sigfillset(&mut sigs) }; + let mut sigs = MaybeUninit::uninit(); + unsafe { libc::sigfillset(sigs.as_mut_ptr()) }; // pselect expects timeouts in nanoseconds. const NSEC_PER_MSEC: u64 = 1000 * 1000; @@ -1329,27 +1330,27 @@ fn readch_timed(&mut self, wait_time_ms: usize) -> Option { }; // We have one fd of interest. - let mut fdset: libc::fd_set = unsafe { std::mem::zeroed() }; + let mut fdset = MaybeUninit::uninit(); let in_fd = self.get_in_fd(); unsafe { - libc::FD_ZERO(&mut fdset); - libc::FD_SET(in_fd, &mut fdset); + libc::FD_ZERO(fdset.as_mut_ptr()); + libc::FD_SET(in_fd, fdset.as_mut_ptr()); }; let res = unsafe { libc::pselect( in_fd + 1, - &mut fdset, + fdset.as_mut_ptr(), ptr::null_mut(), ptr::null_mut(), &timeout, - &sigs, + sigs.as_ptr(), ) }; // Prevent signal starvation on WSL causing the `torn_escapes.py` test to fail if is_windows_subsystem_for_linux(WSL::V1) { // Merely querying the current thread's sigmask is sufficient to deliver a pending signal - let _ = unsafe { libc::pthread_sigmask(0, ptr::null(), &mut sigs) }; + let _ = unsafe { libc::pthread_sigmask(0, ptr::null(), sigs.as_mut_ptr()) }; } if res > 0 { return Some(self.readch());