1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 01:37:35 +00: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:
asynts 2020-09-05 16:39:56 +02:00 committed by Andreas Kling
parent 5d85be7ed4
commit 6de63782c7
8 changed files with 24 additions and 3 deletions

View file

@ -189,8 +189,8 @@ DeflateDecompressor::~DeflateDecompressor()
size_t DeflateDecompressor::read(Bytes bytes)
{
// FIXME: There are surely a ton of bugs because we don't check for read errors
// very often.
if (has_any_error())
return 0;
if (m_state == State::Idle) {
if (m_read_final_bock)

View file

@ -68,6 +68,9 @@ GzipDecompressor::~GzipDecompressor()
// FIXME: Again, there are surely a ton of bugs because the code doesn't check for read errors.
size_t GzipDecompressor::read(Bytes bytes)
{
if (has_any_error())
return 0;
if (m_current_member.has_value()) {
size_t nread = current_member().m_stream.read(bytes);
current_member().m_checksum.update(bytes.trim(nread));

View file

@ -65,6 +65,9 @@ public:
size_t read(Bytes bytes) override
{
if (has_any_error())
return 0;
auto nread = m_buffered.bytes().copy_trimmed_to(bytes);
m_buffered.bytes().slice(nread, m_buffered.size() - nread).copy_to(m_buffered);