Skip to content

Commit 600d665

Browse files
committed
std.Io.Reader: fix appendRemainingUnlimited
Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader to work.
1 parent 355663f commit 600d665

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/std/Io/Reader.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,11 @@ pub fn appendRemainingUnlimited(
366366
const buffer_contents = r.buffer[r.seek..r.end];
367367
try list.ensureUnusedCapacity(gpa, buffer_contents.len + bump);
368368
list.appendSliceAssumeCapacity(buffer_contents);
369-
r.seek = 0;
370-
r.end = 0;
369+
// If statement protects `ending`.
370+
if (r.end != 0) {
371+
r.seek = 0;
372+
r.end = 0;
373+
}
371374
// From here, we leave `buffer` empty, appending directly to `list`.
372375
var writer: Writer = .{
373376
.buffer = undefined,

lib/std/http/test.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ test "general client/server API coverage" {
414414
log.info("{f} {t} {s}", .{ request.head.method, request.head.version, request.head.target });
415415

416416
const gpa = std.testing.allocator;
417-
const body = try (try request.readerExpectContinue(&.{})).allocRemaining(gpa, .unlimited);
417+
const reader = (try request.readerExpectContinue(&.{}));
418+
const body = try reader.allocRemaining(gpa, .unlimited);
418419
defer gpa.free(body);
419420

420421
if (mem.startsWith(u8, request.head.target, "/get")) {

0 commit comments

Comments
 (0)