summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCore
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2023-01-08 21:57:16 +0100
committerAndrew Kaster <andrewdkaster@gmail.com>2023-01-13 17:34:45 -0700
commit100112134d52437b6ad3ab9e0f1edc1f39f9361c (patch)
treee125ae0fda4cc59667ec56b70037d704bd25c9e7 /Userland/Libraries/LibCore
parentd23f0a7405ee52a627a1c3c84fbd030834ef259b (diff)
downloadserenity-100112134d52437b6ad3ab9e0f1edc1f39f9361c.zip
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.
Diffstat (limited to 'Userland/Libraries/LibCore')
-rw-r--r--Userland/Libraries/LibCore/Stream.cpp12
1 files changed, 4 insertions, 8 deletions
diff --git a/Userland/Libraries/LibCore/Stream.cpp b/Userland/Libraries/LibCore/Stream.cpp
index 6e328b791d..9d9292ccaa 100644
--- a/Userland/Libraries/LibCore/Stream.cpp
+++ b/Userland/Libraries/LibCore/Stream.cpp
@@ -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 {};
}