Skip to content

Commit d8b44f6

Browse files
committed
std.Io.Reader: fix appendRemainingUnlimited
Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader to work.
1 parent 5b2007d commit d8b44f6

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
@@ -367,8 +367,11 @@ pub fn appendRemainingUnlimited(
367367
const buffer_contents = r.buffer[r.seek..r.end];
368368
try list.ensureUnusedCapacity(gpa, buffer_contents.len + bump);
369369
list.appendSliceAssumeCapacity(buffer_contents);
370-
r.seek = 0;
371-
r.end = 0;
370+
// If statement protects `ending`.
371+
if (r.end != 0) {
372+
r.seek = 0;
373+
r.end = 0;
374+
}
372375
// From here, we leave `buffer` empty, appending directly to `list`.
373376
var writer: Writer = .{
374377
.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)