Fix process_alive panic on u32 PID values exceeding i32::MAX

The cast_possible_wrap lint fix changed `pid as i32` to
`i32::try_from(pid).unwrap()`, but the unwrap panics when the PID
exceeds i32::MAX (e.g. u32::MAX used in tests). Return false instead
since such values are not valid Unix PIDs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Bryan Helmkamp 2026-03-28 15:17:26 -04:00
parent 007d716f2b
commit 91a265c3a5
No known key found for this signature in database

View file

@ -64,7 +64,10 @@ pub(crate) fn launcher_record_is_running(record: &LauncherRecord) -> bool {
#[cfg(unix)]
#[allow(unsafe_code)]
fn process_alive(pid: u32) -> bool {
unsafe { libc::kill(i32::try_from(pid).unwrap(), 0) == 0 }
let Ok(pid) = i32::try_from(pid) else {
return false;
};
unsafe { libc::kill(pid, 0) == 0 }
}
#[cfg(not(unix))]