Skip to content

Commit b3a4074

Browse files
pakessonandrewrk
authored andcommitted
std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed to match the behavior of musl.
1 parent 46f9380 commit b3a4074

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/std/os/bits/dragonfly.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ pub fn WIFEXITED(s: u32) bool {
345345
return WTERMSIG(s) == 0;
346346
}
347347
pub fn WIFSTOPPED(s: u32) bool {
348-
return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
348+
return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
349349
}
350350
pub fn WIFSIGNALED(s: u32) bool {
351351
return (s & 0xffff) -% 1 < 0xff;

lib/std/os/bits/freebsd.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ pub fn WIFEXITED(s: u32) bool {
742742
return WTERMSIG(s) == 0;
743743
}
744744
pub fn WIFSTOPPED(s: u32) bool {
745-
return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
745+
return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
746746
}
747747
pub fn WIFSIGNALED(s: u32) bool {
748748
return (s & 0xffff) -% 1 < 0xff;

lib/std/os/bits/linux.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ pub fn WIFEXITED(s: u32) bool {
10611061
return WTERMSIG(s) == 0;
10621062
}
10631063
pub fn WIFSTOPPED(s: u32) bool {
1064-
return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1064+
return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
10651065
}
10661066
pub fn WIFSIGNALED(s: u32) bool {
10671067
return (s & 0xffff) -% 1 < 0xff;

0 commit comments

Comments
 (0)