Skip to content

Commit 0db7689

Browse files
krobelustgross35
authored andcommitted
Apply modulo 256 to BSD WEXITSTATUS
wait(2p)[^1] says > WEXITSTATUS(status) > If WIFEXITED(status) is true, evaluates to the low-order 8 bits > of the argument passed to _exit(2) or exit(3) by the child. meaning WEXITSTATUS(status) is an 8-bit value. We accidentally return too many bits. For example WEXITSTATUS(-1) returns -1 instead of 255. Fix it, matching the C library and our other WEXITSTATUS implementations. [^1] https://manpage.me/index.cgi?apropos=0&q=wait&sektion=2&manpath=FreeBSD+12-CURRENT+and+Ports&arch=default&format=html Originally reported at fish-shell/fish-shell#10919
1 parent 94d0ee2 commit 0db7689

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/unix/bsd/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ safe_f! {
639639
}
640640

641641
pub {const} fn WEXITSTATUS(status: c_int) -> c_int {
642-
status >> 8
642+
(status >> 8) & 0x00ff
643643
}
644644

645645
pub {const} fn WCOREDUMP(status: c_int) -> bool {

0 commit comments

Comments
 (0)