From 049f709d0b866eda7991f05768ceaf43368c3cde Mon Sep 17 00:00:00 2001 From: asynts Date: Fri, 11 Sep 2020 14:36:12 +0200 Subject: [PATCH] AK: Calculate the chunk index correctly in DuplexMemoryStream. --- AK/MemoryStream.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AK/MemoryStream.h b/AK/MemoryStream.h index 0e9bf11a56f..b58f725855c 100644 --- a/AK/MemoryStream.h +++ b/AK/MemoryStream.h @@ -232,7 +232,7 @@ public: { size_t 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) / 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); nread += chunk_bytes.copy_trimmed_to(bytes.slice(nread)); }