AK: Fix reading across chunks in DuplexMemoryStream

This commit is contained in:
AnotherTest 2020-12-07 10:36:04 +03:30 committed by Andreas Kling
parent cd8268e6fb
commit 3c41487db7
Notes: sideshowbarker 2024-07-19 00:58:29 +09:00

View File

@ -252,7 +252,7 @@ public:
size_t nread = 0; size_t nread = 0;
while (bytes.size() - nread > 0 && m_write_offset - m_read_offset - nread > 0) { while (bytes.size() - nread > 0 && m_write_offset - m_read_offset - nread > 0) {
const auto chunk_index = (m_read_offset - m_base_offset + nread) / chunk_size; const auto chunk_index = (m_read_offset - m_base_offset + nread) / chunk_size;
const auto chunk_bytes = m_chunks[chunk_index].bytes().slice(m_read_offset % chunk_size).trim(m_write_offset - m_read_offset - nread); const auto chunk_bytes = m_chunks[chunk_index].bytes().slice((m_read_offset + nread) % chunk_size).trim(m_write_offset - m_read_offset - nread);
nread += chunk_bytes.copy_trimmed_to(bytes.slice(nread)); nread += chunk_bytes.copy_trimmed_to(bytes.slice(nread));
} }
@ -279,8 +279,7 @@ public:
return false; return false;
} }
read(bytes); return read(bytes) == bytes.size();
return true;
} }
size_t write(ReadonlyBytes bytes) override size_t write(ReadonlyBytes bytes) override