authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-10 21:28:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-10 21:32:44-07:00
log4ea1aaf7982b9dcb3388058f3113de2856192575
tree0f9500e7d8afc73b83db6e1608ba721837ae8e5a
parente7a418e13155cf2568c6b64d9d51ad61db8dd37b

std.Io.net: use the appropriate error code

Previous commit fixed the crash but used this error code: ``` /// The interface name is longer than the host operating system supports. NameTooLong, ``` More appropriate error code based on the documentation is: ``` /// If this is returned, more detailed diagnostics can be obtained by /// calling the `Parsed.init` function. ParseFailed, ```

2 files changed, 3 insertions(+), 3 deletions(-)

lib/std/Io/net.zig+2-2
......@@ -512,7 +512,7 @@ pub const Ip6Address = struct {
512512 // Has to be u16 elements to handle 3-digit hex numbers from compression.
513513 var parts: [8]u16 = @splat(0);
514514 var parts_i: u8 = 0;
515 var text_i: usize = 0;
515 var text_i: u8 = 0;
516516 var digit_i: u8 = 0;
517517 var compress_start: ?u8 = null;
518518 var interface_name_text: ?[]const u8 = null;
......@@ -576,7 +576,7 @@ pub const Ip6Address = struct {
576576 const name = text[text_i..];
577577 if (name.len == 0) return .incomplete;
578578 interface_name_text = name;
579 text_i = text.len;
579 text_i = std.math.cast(u8, text.len) orelse return .{ .overflow = text.len };
580580 continue :state .end;
581581 },
582582 else => return .{ .invalid_byte = text_i },
lib/std/Io/net/test.zig+1-1
......@@ -94,7 +94,7 @@ test "invalid but parseable IPv6 scope ids" {
9494
9595test "oversized IPv6 scope id" {
9696 const long_scope: [256]u8 = @splat('a');
97 try testing.expectError(error.NameTooLong, net.IpAddress.resolveIp6(testing.io, "ff01::fb%" ++ &long_scope, 0));
97 try testing.expectError(error.ParseFailed, net.IpAddress.resolveIp6(testing.io, "ff01::fb%" ++ &long_scope, 0));
9898}
9999
100100test "parse and render IPv4 addresses" {