authorgravatar for ben@benburkert.comBen Burkert <ben@benburkert.com> 2026-08-31 09:30:25-04:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-09-27 02:23:48+02:00
log9b08aca878557bf390cf8322b28ce069d41a5e3f
treebd3c6264c242db611b67f7224bac01b446e6e7d7
parent8e7153ba30606952bcced8b1c876d216bc7aaf27

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.

1 files changed, 6 insertions(+), 0 deletions(-)

lib/std/testing.zig+6
......@@ -1306,11 +1306,14 @@ pub const Reader = struct {
13061306
13071307/// A `Io.Reader` that gets its data from another `Io.Reader`, and always
13081308/// writes to its own buffer (and returns 0) during `stream` and `readVec`.
1309/// Note: zero length buffers are not supported.
13091310pub const ReaderIndirect = struct {
13101311 in: *Io.Reader,
13111312 interface: Io.Reader,
13121313
13131314 pub fn init(in: *Io.Reader, buffer: []u8) ReaderIndirect {
1315 assert(buffer.len > 0);
1316
13141317 return .{
13151318 .in = in,
13161319 .interface = .{
......@@ -1366,11 +1369,14 @@ pub const ReaderIndirect = struct {
13661369
13671370/// A `Io.Writer` that writes its data to another `Io.Writer`, and only
13681371/// writes new data to its own buffer during `drain`.
1372/// Note: zero length buffers are not supported.
13691373pub const WriterIndirect = struct {
13701374 out: *Io.Writer,
13711375 interface: Io.Writer,
13721376
13731377 pub fn init(out: *Io.Writer, buffer: []u8) WriterIndirect {
1378 assert(buffer.len > 0);
1379
13741380 return .{
13751381 .out = out,
13761382 .interface = .{