1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:17:44 +00:00

LibCore: Make not discarding all requested bytes from a stream an error

This commit is contained in:
Tim Schumacher 2022-12-11 19:47:49 +01:00 committed by Andreas Kling
parent 9a3e95785e
commit 3fccf2481c
2 changed files with 6 additions and 1 deletions

View file

@ -82,6 +82,9 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
Array<u8, continuous_read_size> buffer;
while (discarded_bytes > 0) {
if (is_eof())
return Error::from_string_literal("Reached end-of-file before reading all discarded bytes");
auto slice = TRY(read(buffer.span().slice(0, min(discarded_bytes, continuous_read_size))));
discarded_bytes -= slice.size();
}