Skip to content

Commit

Permalink
std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
Browse files Browse the repository at this point in the history
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
  • Loading branch information
pakesson authored and andrewrk committed Sep 3, 2021
1 parent 46f9380 commit b3a4074
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/std/os/bits/dragonfly.zig
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub fn WIFEXITED(s: u32) bool {
return WTERMSIG(s) == 0;
}
pub fn WIFSTOPPED(s: u32) bool {
return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
}
pub fn WIFSIGNALED(s: u32) bool {
return (s & 0xffff) -% 1 < 0xff;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/os/bits/freebsd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ pub fn WIFEXITED(s: u32) bool {
return WTERMSIG(s) == 0;
}
pub fn WIFSTOPPED(s: u32) bool {
return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
}
pub fn WIFSIGNALED(s: u32) bool {
return (s & 0xffff) -% 1 < 0xff;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/os/bits/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ pub fn WIFEXITED(s: u32) bool {
return WTERMSIG(s) == 0;
}
pub fn WIFSTOPPED(s: u32) bool {
return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
}
pub fn WIFSIGNALED(s: u32) bool {
return (s & 0xffff) -% 1 < 0xff;
Expand Down

0 comments on commit b3a4074

Please # to comment.