From b305a51c90dc6551f57d5705d78100feca9e1f87 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 11 Sep 2019 19:33:51 +0200 Subject: [PATCH] CIODevice: read_all() should return a null ByteBuffer when nothing read We were returning a zero-length ByteBuffer in some cases. We should be consistent about this and always return a null ByteBuffer if nothing was read at all. --- Libraries/LibCore/CIODevice.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Libraries/LibCore/CIODevice.cpp b/Libraries/LibCore/CIODevice.cpp index 0f69fb6cd6..6b7f042f8b 100644 --- a/Libraries/LibCore/CIODevice.cpp +++ b/Libraries/LibCore/CIODevice.cpp @@ -127,7 +127,7 @@ ByteBuffer CIODevice::read_all() int nread = ::read(m_fd, read_buffer, sizeof(read_buffer)); if (nread < 0) { set_error(errno); - return ByteBuffer::copy(data.data(), data.size()); + break; } if (nread == 0) { set_eof(true); @@ -135,6 +135,8 @@ ByteBuffer CIODevice::read_all() } data.append((const u8*)read_buffer, nread); } + if (data.is_empty()) + return {}; return ByteBuffer::copy(data.data(), data.size()); }