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-08-31 22:03:54-04:00
log4f0aa7d639e099b18df583cb984412037fbb1dbe
tree1ef3e04948909487d22bce82d65d96d362ec4001
parent3b9ec4e4df634b17268034a6a5527c11cf67e54b

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
...@@ -348,7 +348,7 @@ pub fn WIFEXITED(s: u32) bool {...@@ -348,7 +348,7 @@ pub fn WIFEXITED(s: u32) bool {
348 return WTERMSIG(s) == 0;348 return WTERMSIG(s) == 0;
349}349}
350pub fn WIFSTOPPED(s: u32) bool {350pub fn WIFSTOPPED(s: u32) bool {
351 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;351 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
352}352}
353pub fn WIFSIGNALED(s: u32) bool {353pub fn WIFSIGNALED(s: u32) bool {
354 return (s & 0xffff) -% 1 < 0xff;354 return (s & 0xffff) -% 1 < 0xff;
lib/std/os/bits/freebsd.zig+1-1
...@@ -741,7 +741,7 @@ pub fn WIFEXITED(s: u32) bool {...@@ -741,7 +741,7 @@ pub fn WIFEXITED(s: u32) bool {
741 return WTERMSIG(s) == 0;741 return WTERMSIG(s) == 0;
742}742}
743pub fn WIFSTOPPED(s: u32) bool {743pub fn WIFSTOPPED(s: u32) bool {
744 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;744 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
745}745}
746pub fn WIFSIGNALED(s: u32) bool {746pub fn WIFSIGNALED(s: u32) bool {
747 return (s & 0xffff) -% 1 < 0xff;747 return (s & 0xffff) -% 1 < 0xff;
lib/std/os/bits/linux.zig+1-1
...@@ -1066,7 +1066,7 @@ pub fn WIFEXITED(s: u32) bool {...@@ -1066,7 +1066,7 @@ pub fn WIFEXITED(s: u32) bool {
1066 return WTERMSIG(s) == 0;1066 return WTERMSIG(s) == 0;
1067}1067}
1068pub fn WIFSTOPPED(s: u32) bool {1068pub fn WIFSTOPPED(s: u32) bool {
1069 return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;1069 return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1070}1070}
1071pub fn WIFSIGNALED(s: u32) bool {1071pub fn WIFSIGNALED(s: u32) bool {
1072 return (s & 0xffff) -% 1 < 0xff;1072 return (s & 0xffff) -% 1 < 0xff;