mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 00:08:56 +00:00
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
This commit is contained in:
parent
73a0b5441b
commit
2b73c28cec
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user