-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Description
Zig Version
0.15.2
Steps to Reproduce and Observed Behavior
Run the following test:
test "discardAll that has to call discard multiple times on an indirect reader" {
var fr: Reader = .fixed("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
var indirect_buffer: [3]u8 = undefined;
var tri: std.testing.ReaderIndirect = .init(&fr, &indirect_buffer);
const r = &tri.interface;
try r.discardAll(10);
}
An assert trips in defaultDiscard:
std\Io\Reader.zig:199:11: 0x7ff6564c14d9 in defaultDiscard
assert(r.seek == r.end);
^
Expected Behavior
Test should pass and no assert should trip.
Notes
The defaultDiscard implementation rightly asserts that the buffer is empty before being called, however, it goes on to call stream which for some implementations can read into the buffer. Consequently, if you call discardAll with a size bigger than the buffer, it can call defaultDiscard multiple times in succession which will trigger the assert if the previous one left data in the buffer. Solution is probably to have defaultDiscard clear the buffer after calling stream.
squeek502
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behaviorstandard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.