From 997e745e87608467a8c5bd1f60da871743b1bbb6 Mon Sep 17 00:00:00 2001 From: Tim Schumacher Date: Tue, 4 Apr 2023 19:42:42 +0200 Subject: [PATCH] AK: Properly limit the internal seekback span for CircularBuffer I was originally thinking in the wrong direction when adding this limit, we can at most read from the buffer until we reach the current write head. Since that write head is the reference point for the distance, we need to limit ourselves to that instead of the seekback limit (which is the maximum of how far back the distance can be). --- AK/CircularBuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AK/CircularBuffer.cpp b/AK/CircularBuffer.cpp index 075ffd4e25f..6d8aa4d742c 100644 --- a/AK/CircularBuffer.cpp +++ b/AK/CircularBuffer.cpp @@ -110,7 +110,7 @@ ReadonlyBytes CircularBuffer::next_read_span_with_seekback(size_t distance) cons // Note: We are adding the capacity once here to ensure that we can wrap around the negative space by using modulo. auto read_offset = (capacity() + m_reading_head + m_used_space - distance) % capacity(); - return m_buffer.span().slice(read_offset, min(capacity() - read_offset, m_seekback_limit)); + return m_buffer.span().slice(read_offset, min(capacity() - read_offset, distance)); } size_t CircularBuffer::write(ReadonlyBytes bytes)