From 9b08aca878557bf390cf8322b28ce069d41a5e3f Mon Sep 17 00:00:00 2001 From: Ben Burkert Date: Mon, 31 Aug 2026 09:30:25 -0400 Subject: [PATCH] Assert testing.{Reader,Writer}Indirect initialized with non-zero buffer Both std.testing.ReaderIndirect & std.testing.WriterIndirect require a non-zero length buffer because their purpose is to exercise internal buffering, not to be a pass-through Reader/Writer. Asserting a non-zero buffer length prevents unintended behavior like infinite loops on certain operations. --- lib/std/testing.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/std/testing.zig b/lib/std/testing.zig index d7ee376afb152587681de2ea8875c2c653a72f2e..53c52b71073a80a1360ca4d9bd39b9e2d603eb1d 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -1306,11 +1306,14 @@ pub const Reader = struct { /// A `Io.Reader` that gets its data from another `Io.Reader`, and always /// writes to its own buffer (and returns 0) during `stream` and `readVec`. +/// Note: zero length buffers are not supported. pub const ReaderIndirect = struct { in: *Io.Reader, interface: Io.Reader, pub fn init(in: *Io.Reader, buffer: []u8) ReaderIndirect { + assert(buffer.len > 0); + return .{ .in = in, .interface = .{ @@ -1366,11 +1369,14 @@ pub const ReaderIndirect = struct { /// A `Io.Writer` that writes its data to another `Io.Writer`, and only /// writes new data to its own buffer during `drain`. +/// Note: zero length buffers are not supported. pub const WriterIndirect = struct { out: *Io.Writer, interface: Io.Writer, pub fn init(out: *Io.Writer, buffer: []u8) WriterIndirect { + assert(buffer.len > 0); + return .{ .out = out, .interface = .{ -- 2.54.0