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.
This commit is contained in:
Andreas Kling 2019-09-11 19:33:51 +02:00
parent 825fa3463c
commit b305a51c90
Notes: sideshowbarker 2024-07-19 12:09:40 +09:00

View File

@ -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());
}