aboutsummaryrefslogtreecommitdiff
path: root/lib/std/net.zig
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-12-21 16:40:30 +0200
committerVeikka Tuominen <git@vexu.eu>2022-12-27 15:13:14 +0200
commit622311fb9ac7ee6d93dcb8cda4b608751f7e092a (patch)
treeef54a9f6bc53919a4ef4f01aae2d9e3573aad871 /lib/std/net.zig
parent54160e7f6aecb4628df633ceaef4c6d956429a3d (diff)
downloadzig-622311fb9ac7ee6d93dcb8cda4b608751f7e092a.tar.gz
zig-622311fb9ac7ee6d93dcb8cda4b608751f7e092a.zip
update uses of overflow arithmetic builtins
Diffstat (limited to 'lib/std/net.zig')
-rw-r--r--lib/std/net.zig36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/std/net.zig b/lib/std/net.zig
index 6818b91d5a..4a0582e7f5 100644
--- a/lib/std/net.zig
+++ b/lib/std/net.zig
@@ -321,11 +321,15 @@ pub const Ip6Address = extern struct {
if (scope_id) {
if (c >= '0' and c <= '9') {
const digit = c - '0';
- if (@mulWithOverflow(u32, result.sa.scope_id, 10, &result.sa.scope_id)) {
- return error.Overflow;
+ {
+ const ov = @mulWithOverflow(result.sa.scope_id, 10);
+ if (ov[1] != 0) return error.Overflow;
+ result.sa.scope_id = ov[0];
}
- if (@addWithOverflow(u32, result.sa.scope_id, digit, &result.sa.scope_id)) {
- return error.Overflow;
+ {
+ const ov = @addWithOverflow(result.sa.scope_id, digit);
+ if (ov[1] != 0) return error.Overflow;
+ result.sa.scope_id = ov[0];
}
} else {
return error.InvalidCharacter;
@@ -377,11 +381,15 @@ pub const Ip6Address = extern struct {
return result;
} else {
const digit = try std.fmt.charToDigit(c, 16);
- if (@mulWithOverflow(u16, x, 16, &x)) {
- return error.Overflow;
+ {
+ const ov = @mulWithOverflow(x, 16);
+ if (ov[1] != 0) return error.Overflow;
+ x = ov[0];
}
- if (@addWithOverflow(u16, x, digit, &x)) {
- return error.Overflow;
+ {
+ const ov = @addWithOverflow(x, digit);
+ if (ov[1] != 0) return error.Overflow;
+ x = ov[0];
}
saw_any_digits = true;
}
@@ -492,11 +500,15 @@ pub const Ip6Address = extern struct {
return result;
} else {
const digit = try std.fmt.charToDigit(c, 16);
- if (@mulWithOverflow(u16, x, 16, &x)) {
- return error.Overflow;
+ {
+ const ov = @mulWithOverflow(x, 16);
+ if (ov[1] != 0) return error.Overflow;
+ x = ov[0];
}
- if (@addWithOverflow(u16, x, digit, &x)) {
- return error.Overflow;
+ {
+ const ov = @addWithOverflow(x, digit);
+ if (ov[1] != 0) return error.Overflow;
+ x = ov[0];
}
saw_any_digits = true;
}