Skip to content

Commit 4f0aa7d

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 3b9ec4e commit 4f0aa7d

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
@@ -348,7 +348,7 @@ pub fn WIFEXITED(s: u32) bool {
348348
return WTERMSIG(s) == 0;
349349
}
350350
pub fn WIFSTOPPED(s: u32) bool {
351-
return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
351+
return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
352352
}
353353
pub fn WIFSIGNALED(s: u32) bool {
354354
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
@@ -741,7 +741,7 @@ pub fn WIFEXITED(s: u32) bool {
741741
return WTERMSIG(s) == 0;
742742
}
743743
pub fn WIFSTOPPED(s: u32) bool {
744-
return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
744+
return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
745745
}
746746
pub fn WIFSIGNALED(s: u32) bool {
747747
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
@@ -1066,7 +1066,7 @@ pub fn WIFEXITED(s: u32) bool {
10661066
return WTERMSIG(s) == 0;
10671067
}
10681068
pub fn WIFSTOPPED(s: u32) bool {
1069-
return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1069+
return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
10701070
}
10711071
pub fn WIFSIGNALED(s: u32) bool {
10721072
return (s & 0xffff) -% 1 < 0xff;

0 commit comments

Comments
 (0)