mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-22 20:31:15 -03:00
fix: pointer and signal handler casts
- avoid UB from `usize` → pointer cast - use correct type for `sa_sigaction` Closes #12488
This commit is contained in:
committed by
Johannes Altmanninger
parent
eab84c896e
commit
53e1718a68
@@ -400,8 +400,10 @@ fn test_char() {
|
||||
|
||||
#[test]
|
||||
fn test_ptr() {
|
||||
assert_fmt!("%p", core::ptr::null::<u8>() => "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]
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user