mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibCore: Allow zero-sized spans in Stream::*_entire_buffer
There is no particular reason why we shouldn't allow zero-sized reads or writes here, and this actually might cause issues with our common stream-to-stream copy pattern if we end up at an unfortunate offset where the next read would be zero-sized and trigger EOF only after that.
This commit is contained in:
parent
d23f0a7405
commit
100112134d
Notes:
sideshowbarker
2024-07-17 04:10:16 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/100112134d Pull-request: https://github.com/SerenityOS/serenity/pull/16917 Reviewed-by: https://github.com/ADKaster ✅
1 changed files with 4 additions and 8 deletions
|
@ -24,10 +24,8 @@ namespace Core::Stream {
|
|||
|
||||
ErrorOr<void> Stream::read_entire_buffer(Bytes buffer)
|
||||
{
|
||||
VERIFY(buffer.size());
|
||||
|
||||
size_t nread = 0;
|
||||
do {
|
||||
while (nread < buffer.size()) {
|
||||
if (is_eof())
|
||||
return Error::from_string_literal("Reached end-of-file before filling the entire buffer");
|
||||
|
||||
|
@ -41,7 +39,7 @@ ErrorOr<void> Stream::read_entire_buffer(Bytes buffer)
|
|||
}
|
||||
|
||||
nread += result.value().size();
|
||||
} while (nread < buffer.size());
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -93,10 +91,8 @@ ErrorOr<void> Stream::discard(size_t discarded_bytes)
|
|||
|
||||
ErrorOr<void> Stream::write_entire_buffer(ReadonlyBytes buffer)
|
||||
{
|
||||
VERIFY(buffer.size());
|
||||
|
||||
size_t nwritten = 0;
|
||||
do {
|
||||
while (nwritten < buffer.size()) {
|
||||
auto result = write(buffer.slice(nwritten));
|
||||
if (result.is_error()) {
|
||||
if (result.error().is_errno() && result.error().code() == EINTR) {
|
||||
|
@ -107,7 +103,7 @@ ErrorOr<void> Stream::write_entire_buffer(ReadonlyBytes buffer)
|
|||
}
|
||||
|
||||
nwritten += result.value();
|
||||
} while (nwritten < buffer.size());
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue