zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 4ea1aaf7982b9dcb3388058f3113de2856192575 (tree)
parent e7a418e13155cf2568c6b64d9d51ad61db8dd37b
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Wed, 10 Jun 2026 21:28:36 -0700

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,
```

Diffstat:
Mlib/std/Io/net.zig | 4++--
Mlib/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 @@ -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 @@ -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" {