authorgravatar for philip.akesson@gmail.comPhilip Åkesson <philip.akesson@gmail.com> 2021-08-24 21:34:43+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-03 10:18:28-07:00
logb3a40743580c1aca6b6f5d212d3b307d4fd1f16b
tree9ecbcef12adf55c410e8d849762d90073de77dc8
parent46f93807aaf4d9c1ea2000cda5ad46ea6f212b3e

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.

3 files changed, 3 insertions(+), 3 deletions(-)

lib/std/os/bits/dragonfly.zig+1-1
......@@ -345,7 +345,7 @@ pub fn WIFEXITED(s: u32) bool {
345345 return WTERMSIG(s) == 0;
346346}
347347pub fn WIFSTOPPED(s: u32) bool {
348 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
348 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
349349}
350350pub fn WIFSIGNALED(s: u32) bool {
351351 return (s & 0xffff) -% 1 < 0xff;
lib/std/os/bits/freebsd.zig+1-1
......@@ -742,7 +742,7 @@ pub fn WIFEXITED(s: u32) bool {
742742 return WTERMSIG(s) == 0;
743743}
744744pub fn WIFSTOPPED(s: u32) bool {
745 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
745 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
746746}
747747pub fn WIFSIGNALED(s: u32) bool {
748748 return (s & 0xffff) -% 1 < 0xff;
lib/std/os/bits/linux.zig+1-1
......@@ -1061,7 +1061,7 @@ pub fn WIFEXITED(s: u32) bool {
10611061 return WTERMSIG(s) == 0;
10621062}
10631063pub fn WIFSTOPPED(s: u32) bool {
1064 return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1064 return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
10651065}
10661066pub fn WIFSIGNALED(s: u32) bool {
10671067 return (s & 0xffff) -% 1 < 0xff;