mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
Streams: Consistent behaviour when reading from stream with error.
The streaming operator doesn't short-circuit, consider the following
snippet:
void foo(InputStream& stream) {
int a, b;
stream >> a >> b;
}
If the first read fails, the second is called regardless. It should be
well defined what happens in this case: nothing.
This commit is contained in:
Notes:
sideshowbarker
2024-07-19 02:53:43 +09:00
Author: https://github.com/asynts Commit: https://github.com/SerenityOS/serenity/commit/6de63782c79 Pull-request: https://github.com/SerenityOS/serenity/pull/3405
@@ -44,6 +44,9 @@ public:
|
||||
|
||||
size_t read(Bytes bytes) override
|
||||
{
|
||||
if (has_any_error())
|
||||
return 0;
|
||||
|
||||
const auto count = min(bytes.size(), remaining());
|
||||
__builtin_memcpy(bytes.data(), m_bytes.data() + m_offset, count);
|
||||
m_offset += count;
|
||||
@@ -239,6 +242,9 @@ public:
|
||||
|
||||
size_t read(Bytes bytes) override
|
||||
{
|
||||
if (has_any_error())
|
||||
return 0;
|
||||
|
||||
const auto nread = read_without_consuming(bytes);
|
||||
|
||||
m_read_offset += nread;
|
||||
|
||||
Reference in New Issue
Block a user