From 4f0aa7d639e099b18df583cb984412037fbb1dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20=C3=85kesson?= Date: Tue, 24 Aug 2021 21:34:43 +0200 Subject: [PATCH] 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. --- lib/std/os/bits/dragonfly.zig | 2 +- lib/std/os/bits/freebsd.zig | 2 +- lib/std/os/bits/linux.zig | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/os/bits/dragonfly.zig b/lib/std/os/bits/dragonfly.zig index c13a3aea91..4fe52a6f0a 100644 --- a/lib/std/os/bits/dragonfly.zig +++ b/lib/std/os/bits/dragonfly.zig @@ -348,7 +348,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; diff --git a/lib/std/os/bits/freebsd.zig b/lib/std/os/bits/freebsd.zig index 51b7ef9f4d..b4ff21fbf0 100644 --- a/lib/std/os/bits/freebsd.zig +++ b/lib/std/os/bits/freebsd.zig @@ -741,7 +741,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; diff --git a/lib/std/os/bits/linux.zig b/lib/std/os/bits/linux.zig index 653fb8f1e1..dfc2b5065c 100644 --- a/lib/std/os/bits/linux.zig +++ b/lib/std/os/bits/linux.zig @@ -1066,7 +1066,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;