authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2025-08-28 00:26:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-08-28 07:56:50-07:00
log2b73c28cec9a5c75ab064f1ebd88b12aa64d22dd
tree75d9a6f12c9349068068246a153537425d318988
parent73a0b5441be3dc6adb666ca672f3c4f7972cf73e

Reader.appendRemaining: Take ownership of the full allocated slice

Before this commit, calling appendRemaining with an ArrayList where list.items.len != list.capacity could result in illegal behavior if the Writer.Allocating resized the list during the appendRemaining call. Fixes #25057

1 files changed, 2 insertions(+), 2 deletions(-)

lib/std/Io/Reader.zig+2-2
......@@ -308,7 +308,7 @@ pub fn appendRemaining(
308308 list: *ArrayList(u8),
309309 limit: Limit,
310310) LimitedAllocError!void {
311 var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.items);
311 var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.allocatedSlice());
312312 a.writer.end = list.items.len;
313313 list.* = .empty;
314314 defer {
......@@ -332,7 +332,7 @@ pub fn appendRemaining(
332332pub const UnlimitedAllocError = Allocator.Error || ShortError;
333333
334334pub fn appendRemainingUnlimited(r: *Reader, gpa: Allocator, list: *ArrayList(u8)) UnlimitedAllocError!void {
335 var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.items);
335 var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.allocatedSlice());
336336 a.writer.end = list.items.len;
337337 list.* = .empty;
338338 defer {