zig

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

commit 2b73c28cec9a5c75ab064f1ebd88b12aa64d22dd (tree)
parent 73a0b5441be3dc6adb666ca672f3c4f7972cf73e
Author: Ryan Liptak <squeek502@hotmail.com>
Date:   Thu, 28 Aug 2025 00:26:57 -0700

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

Diffstat:
Mlib/std/Io/Reader.zig | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/std/Io/Reader.zig b/lib/std/Io/Reader.zig @@ -308,7 +308,7 @@ pub fn appendRemaining( list: *ArrayList(u8), limit: Limit, ) LimitedAllocError!void { - var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.items); + var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.allocatedSlice()); a.writer.end = list.items.len; list.* = .empty; defer { @@ -332,7 +332,7 @@ pub fn appendRemaining( pub const UnlimitedAllocError = Allocator.Error || ShortError; pub fn appendRemainingUnlimited(r: *Reader, gpa: Allocator, list: *ArrayList(u8)) UnlimitedAllocError!void { - var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.items); + var a: std.Io.Writer.Allocating = .initOwnedSlice(gpa, list.allocatedSlice()); a.writer.end = list.items.len; list.* = .empty; defer {