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 {...@@ -345,7 +345,7 @@ pub fn WIFEXITED(s: u32) bool {
345 return WTERMSIG(s) == 0;345 return WTERMSIG(s) == 0;
346}346}
347pub fn WIFSTOPPED(s: u32) bool {347pub fn WIFSTOPPED(s: u32) bool {
348 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;348 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
349}349}
350pub fn WIFSIGNALED(s: u32) bool {350pub fn WIFSIGNALED(s: u32) bool {
351 return (s & 0xffff) -% 1 < 0xff;351 return (s & 0xffff) -% 1 < 0xff;
lib/std/os/bits/freebsd.zig+1-1
...@@ -742,7 +742,7 @@ pub fn WIFEXITED(s: u32) bool {...@@ -742,7 +742,7 @@ pub fn WIFEXITED(s: u32) bool {
742 return WTERMSIG(s) == 0;742 return WTERMSIG(s) == 0;
743}743}
744pub fn WIFSTOPPED(s: u32) bool {744pub fn WIFSTOPPED(s: u32) bool {
745 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;745 return @truncate(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
746}746}
747pub fn WIFSIGNALED(s: u32) bool {747pub fn WIFSIGNALED(s: u32) bool {
748 return (s & 0xffff) -% 1 < 0xff;748 return (s & 0xffff) -% 1 < 0xff;
lib/std/os/bits/linux.zig+1-1
...@@ -1061,7 +1061,7 @@ pub fn WIFEXITED(s: u32) bool {...@@ -1061,7 +1061,7 @@ pub fn WIFEXITED(s: u32) bool {
1061 return WTERMSIG(s) == 0;1061 return WTERMSIG(s) == 0;
1062}1062}
1063pub fn WIFSTOPPED(s: u32) bool {1063pub fn WIFSTOPPED(s: u32) bool {
1064 return @intCast(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;1064 return @truncate(u16, ((s & 0xffff) *% 0x10001) >> 8) > 0x7f00;
1065}1065}
1066pub fn WIFSIGNALED(s: u32) bool {1066pub fn WIFSIGNALED(s: u32) bool {
1067 return (s & 0xffff) -% 1 < 0xff;1067 return (s & 0xffff) -% 1 < 0xff;