zig

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

commit 8f4229158be69685b49f4e1ac446cd3677a2e63f (tree)
parent d03d2731175c5e775dccaef3ef3329f98c4e2c70
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 30 Jun 2025 15:52:13 -0700

std.io.Writer.Allocating: extra ensure byte

So that when returning from drain there is always capacity for at least
one more byte.

Diffstat:
Mlib/std/io/Writer.zig | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/std/io/Writer.zig b/lib/std/io/Writer.zig @@ -2158,8 +2158,11 @@ pub const Allocating = struct { var list = a.toArrayList(); defer setArrayList(a, list); const start_len = list.items.len; + // Even if we append no data, this function needs to ensure there is more + // capacity in the buffer to avoid infinite loop, hence the +1 in this loop. + assert(data.len != 0); for (data) |bytes| { - list.ensureUnusedCapacity(gpa, bytes.len + splat_len) catch return error.WriteFailed; + list.ensureUnusedCapacity(gpa, bytes.len + splat_len + 1) catch return error.WriteFailed; list.appendSliceAssumeCapacity(bytes); } if (splat == 0) {