Commit b3a4074358

Philip Åkesson <philip.akesson@gmail.com>
2021-08-24 21:34:43
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
Changed files (3)
lib/std/os/bits/dragonfly.zig
@@ -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;
lib/std/os/bits/freebsd.zig
@@ -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;
lib/std/os/bits/linux.zig
@@ -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;