From 4ea1aaf7982b9dcb3388058f3113de2856192575 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 10 Jun 2026 21:28:36 -0700 Subject: [PATCH] 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, ``` --- lib/std/Io/net.zig | 4 ++-- lib/std/Io/net/test.zig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/Io/net.zig b/lib/std/Io/net.zig index 787e3e8c8b475f0c6327440d1781da26e90336db..c32d7dfa5016d16ca6c79ba890c9372fec056c27 100644 --- a/lib/std/Io/net.zig +++ b/lib/std/Io/net.zig @@ -512,7 +512,7 @@ pub const Ip6Address = struct { // Has to be u16 elements to handle 3-digit hex numbers from compression. var parts: [8]u16 = @splat(0); var parts_i: u8 = 0; - var text_i: usize = 0; + var text_i: u8 = 0; var digit_i: u8 = 0; var compress_start: ?u8 = null; var interface_name_text: ?[]const u8 = null; @@ -576,7 +576,7 @@ pub const Ip6Address = struct { const name = text[text_i..]; if (name.len == 0) return .incomplete; interface_name_text = name; - text_i = text.len; + text_i = std.math.cast(u8, text.len) orelse return .{ .overflow = text.len }; continue :state .end; }, else => return .{ .invalid_byte = text_i }, diff --git a/lib/std/Io/net/test.zig b/lib/std/Io/net/test.zig index ddf6a9866c486d550caca51242f4d1f8f692fc11..308dc1a32670e207e72511d0128b634972050e6a 100644 --- a/lib/std/Io/net/test.zig +++ b/lib/std/Io/net/test.zig @@ -94,7 +94,7 @@ test "invalid but parseable IPv6 scope ids" { test "oversized IPv6 scope id" { const long_scope: [256]u8 = @splat('a'); - try testing.expectError(error.NameTooLong, net.IpAddress.resolveIp6(testing.io, "ff01::fb%" ++ &long_scope, 0)); + try testing.expectError(error.ParseFailed, net.IpAddress.resolveIp6(testing.io, "ff01::fb%" ++ &long_scope, 0)); } test "parse and render IPv4 addresses" { -- 2.54.0