From 53e1718a6801fc277b54b02ceeb4b659df313b64 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Thu, 26 Feb 2026 21:43:23 +0000 Subject: [PATCH] fix: pointer and signal handler casts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - avoid UB from `usize` → pointer cast - use correct type for `sa_sigaction` Closes #12488 --- crates/printf/src/tests.rs | 6 ++++-- src/signal.rs | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/printf/src/tests.rs b/crates/printf/src/tests.rs index 5d1e41bd9..2d503b781 100644 --- a/crates/printf/src/tests.rs +++ b/crates/printf/src/tests.rs @@ -400,8 +400,10 @@ fn test_char() { #[test] fn test_ptr() { - assert_fmt!("%p", core::ptr::null::() => "0"); - assert_fmt!("%p", 0xDEADBEEF_usize as *const u8 => "0xdeadbeef"); + assert_fmt!("%p", core::ptr::null::<()>() => "0"); + + let tmp = core::ptr::without_provenance::<()>(0xDEADBEEF); + assert_fmt!("%p", tmp => "0xdeadbeef"); } #[test] diff --git a/src/signal.rs b/src/signal.rs index 4837ec432..8e40fa10c 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -157,7 +157,7 @@ fn sigaction(sig: i32, act: &libc::sigaction, oact: *mut libc::sigaction) -> lib } fn set_interactive_handlers() { - let signal_handler: usize = fish_signal_handler as *const () as usize; + let signal_handler: usize = fish_signal_handler as *const () as libc::sighandler_t; let mut act: libc::sigaction = unsafe { std::mem::zeroed() }; let mut oact: libc::sigaction = unsafe { std::mem::zeroed() }; act.sa_flags = 0; @@ -221,12 +221,12 @@ pub fn signal_set_handlers(interactive: bool) { sigaction(libc::SIGQUIT, &act, nullptr); // Apply our SIGINT handler. - act.sa_sigaction = fish_signal_handler as *const () as usize; + act.sa_sigaction = fish_signal_handler as *const () as libc::sighandler_t; act.sa_flags = libc::SA_SIGINFO; sigaction(libc::SIGINT, &act, nullptr); // Whether or not we're interactive we want SIGCHLD to not interrupt restartable syscalls. - act.sa_sigaction = fish_signal_handler as *const () as usize; + act.sa_sigaction = fish_signal_handler as *const () as libc::sighandler_t; act.sa_flags = libc::SA_SIGINFO | libc::SA_RESTART; if sigaction(libc::SIGCHLD, &act, nullptr) != 0 { perror("sigaction"); @@ -279,7 +279,7 @@ pub fn signal_handle(sig: Signal) { act.sa_flags = 0; unsafe { libc::sigemptyset(&mut act.sa_mask) }; act.sa_flags = libc::SA_SIGINFO; - act.sa_sigaction = fish_signal_handler as *const () as usize; + act.sa_sigaction = fish_signal_handler as *const () as libc::sighandler_t; sigaction(sig, &act, std::ptr::null_mut()); }