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 {...@@ -1306,11 +1306,14 @@ pub const Reader = struct {
13061306
1307/// A `Io.Reader` that gets its data from another `Io.Reader`, and always1307/// A `Io.Reader` that gets its data from another `Io.Reader`, and always
1308/// writes to its own buffer (and returns 0) during `stream` and `readVec`.1308/// writes to its own buffer (and returns 0) during `stream` and `readVec`.
1309/// Note: zero length buffers are not supported.
1309pub const ReaderIndirect = struct {1310pub const ReaderIndirect = struct {
1310 in: *Io.Reader,1311 in: *Io.Reader,
1311 interface: Io.Reader,1312 interface: Io.Reader,
13121313
1313 pub fn init(in: *Io.Reader, buffer: []u8) ReaderIndirect {1314 pub fn init(in: *Io.Reader, buffer: []u8) ReaderIndirect {
1315 assert(buffer.len > 0);
1316
1314 return .{1317 return .{
1315 .in = in,1318 .in = in,
1316 .interface = .{1319 .interface = .{
...@@ -1366,11 +1369,14 @@ pub const ReaderIndirect = struct {...@@ -1366,11 +1369,14 @@ pub const ReaderIndirect = struct {
13661369
1367/// A `Io.Writer` that writes its data to another `Io.Writer`, and only1370/// A `Io.Writer` that writes its data to another `Io.Writer`, and only
1368/// writes new data to its own buffer during `drain`.1371/// writes new data to its own buffer during `drain`.
1372/// Note: zero length buffers are not supported.
1369pub const WriterIndirect = struct {1373pub const WriterIndirect = struct {
1370 out: *Io.Writer,1374 out: *Io.Writer,
1371 interface: Io.Writer,1375 interface: Io.Writer,
13721376
1373 pub fn init(out: *Io.Writer, buffer: []u8) WriterIndirect {1377 pub fn init(out: *Io.Writer, buffer: []u8) WriterIndirect {
1378 assert(buffer.len > 0);
1379
1374 return .{1380 return .{
1375 .out = out,1381 .out = out,
1376 .interface = .{1382 .interface = .{