fix: cast ExitStatus to correct type, remove Boxes (#399)

* fix: cast ExitStatus to correct type, remove Boxes

Absolutely no clue why Past Me thought `usize` was the correct type
to convert `ExitStatus` from. Rust docs make it really clear it is a
`c_int` (i32) on Unix.

Past Me also decided both leaking memory with `Box::into_raw` then
unsoundly calling `Box::from_raw` on a pointer to a stack-allocated
array was smart. Dunno why. Loser did not even leave a safety comment
smh.

* fix: use `mem::size_of` to get size of `i32`
This commit is contained in:
En-En 2026-03-16 00:51:05 +00:00 committed by GitHub
parent 309d8e2a29
commit a879e5e089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 12 deletions

View file

@ -102,12 +102,11 @@ impl Drop for Fixture {
let thread = unsafe { ManuallyDrop::take(&mut self.thread) };
// Sending anything to the quit receiver to stop the main loop. Then we guarantee a main
// thread does not use file descriptors which outlive the Fixture's BorrowedFd
let return_ptr = Box::into_raw(Box::new(0_usize)) as usize;
// If the receiver end of the pipe closed, the main thread dropped it, which means that
// thread already terminated
if self
.quit_tx
.write_all(&return_ptr.to_ne_bytes())
.write_all(&0_i32.to_ne_bytes())
.is_err_and(|e| e.kind() != std::io::ErrorKind::BrokenPipe)
{
panic!("could not message the main thread to terminate");