From b294e14ce4b9d1ccab0368eede4f746dfc7c6062 Mon Sep 17 00:00:00 2001 From: Andreas Linz Date: Wed, 16 Dec 2020 21:17:41 +0100 Subject: [PATCH] Truncate user and group ids Calls to `getuid`, `getgid` and their `eid` variants fail to compile on 64bit Linux systems because the return value of the syscall is of `usize` and needs to be truncated to fit the size of `uid_t` that is 32 bit. Thanks to @FireFox317 for figuring this out in Zig's Discord channel! --- lib/std/os/linux.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index f840f6a255be..3beeb0e13c25 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -747,7 +747,7 @@ pub fn getuid() uid_t { if (@hasField(SYS, "getuid32")) { return @as(uid_t, syscall0(.getuid32)); } else { - return @as(uid_t, syscall0(.getuid)); + return @truncate(uid_t, syscall0(.getuid)); } } @@ -755,7 +755,7 @@ pub fn getgid() gid_t { if (@hasField(SYS, "getgid32")) { return @as(gid_t, syscall0(.getgid32)); } else { - return @as(gid_t, syscall0(.getgid)); + return @truncate(gid_t, syscall0(.getgid)); } } @@ -763,7 +763,7 @@ pub fn geteuid() uid_t { if (@hasField(SYS, "geteuid32")) { return @as(uid_t, syscall0(.geteuid32)); } else { - return @as(uid_t, syscall0(.geteuid)); + return @truncate(uid_t, syscall0(.geteuid)); } } @@ -771,7 +771,7 @@ pub fn getegid() gid_t { if (@hasField(SYS, "getegid32")) { return @as(gid_t, syscall0(.getegid32)); } else { - return @as(gid_t, syscall0(.getegid)); + return @truncate(gid_t, syscall0(.getegid)); } }