aboutsummaryrefslogtreecommitdiff
path: root/lib/std/process.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-12-27 13:57:49 -0500
committerGitHub <noreply@github.com>2022-12-27 13:57:49 -0500
commit19056cb6821dd03612628e9220595576878aafe7 (patch)
treeb0e4bc3588abf86e55d343843f77bb891bc816da /lib/std/process.zig
parent55c3efcb58cc153fc3109a61c6949e470b57b81e (diff)
parenta777373bb8d6fd94b54d63f124b7346163b39045 (diff)
downloadzig-19056cb6821dd03612628e9220595576878aafe7.tar.gz
zig-19056cb6821dd03612628e9220595576878aafe7.zip
Merge pull request #14024 from Vexu/overflow-arithmetic
Make overflow arithmetic builtins return tuples
Diffstat (limited to 'lib/std/process.zig')
-rw-r--r--lib/std/process.zig24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/std/process.zig b/lib/std/process.zig
index 23fad9e8c6..849596ebfa 100644
--- a/lib/std/process.zig
+++ b/lib/std/process.zig
@@ -1023,8 +1023,16 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
'0'...'9' => byte - '0',
else => return error.CorruptPasswordFile,
};
- if (@mulWithOverflow(u32, uid, 10, &uid)) return error.CorruptPasswordFile;
- if (@addWithOverflow(u32, uid, digit, &uid)) return error.CorruptPasswordFile;
+ {
+ const ov = @mulWithOverflow(uid, 10);
+ if (ov[1] != 0) return error.CorruptPasswordFile;
+ uid = ov[0];
+ }
+ {
+ const ov = @addWithOverflow(uid, digit);
+ if (ov[1] != 0) return error.CorruptPasswordFile;
+ uid = ov[0];
+ }
},
},
.ReadGroupId => switch (byte) {
@@ -1039,8 +1047,16 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo {
'0'...'9' => byte - '0',
else => return error.CorruptPasswordFile,
};
- if (@mulWithOverflow(u32, gid, 10, &gid)) return error.CorruptPasswordFile;
- if (@addWithOverflow(u32, gid, digit, &gid)) return error.CorruptPasswordFile;
+ {
+ const ov = @mulWithOverflow(gid, 10);
+ if (ov[1] != 0) return error.CorruptPasswordFile;
+ gid = ov[0];
+ }
+ {
+ const ov = @addWithOverflow(gid, digit);
+ if (ov[1] != 0) return error.CorruptPasswordFile;
+ gid = ov[0];
+ }
},
},
}