zig

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

commit abd76938cb8455891c5a69c33edb7060f42001a3 (tree)
parent 9e5048c3a5be479d9ad72d1d004d385f2fdc8615
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon,  4 Aug 2025 20:27:55 -0700

std.Io.Reader: fix appendRemainingUnlimited

Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader
to work.

Diffstat:
Mlib/std/Io/Reader.zig | 7+++++--
Mlib/std/http/test.zig | 3++-
2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/lib/std/Io/Reader.zig b/lib/std/Io/Reader.zig @@ -367,8 +367,11 @@ pub fn appendRemainingUnlimited( const buffer_contents = r.buffer[r.seek..r.end]; try list.ensureUnusedCapacity(gpa, buffer_contents.len + bump); list.appendSliceAssumeCapacity(buffer_contents); - r.seek = 0; - r.end = 0; + // If statement protects `ending`. + if (r.end != 0) { + r.seek = 0; + r.end = 0; + } // From here, we leave `buffer` empty, appending directly to `list`. var writer: Writer = .{ .buffer = undefined, diff --git a/lib/std/http/test.zig b/lib/std/http/test.zig @@ -414,7 +414,8 @@ test "general client/server API coverage" { log.info("{f} {t} {s}", .{ request.head.method, request.head.version, request.head.target }); const gpa = std.testing.allocator; - const body = try (try request.readerExpectContinue(&.{})).allocRemaining(gpa, .unlimited); + const reader = (try request.readerExpectContinue(&.{})); + const body = try reader.allocRemaining(gpa, .unlimited); defer gpa.free(body); if (mem.startsWith(u8, request.head.target, "/get")) {