diff options
author | Tim Schumacher <timschumi@gmx.de> | 2023-04-04 18:29:43 +0200 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-04-05 07:30:38 -0400 |
commit | 767fb01a8cf54f0760e5bbf408eb89d67239575d (patch) | |
tree | c1ebcd4b475517fc2df21c83e349a35082e045c9 /AK/CircularBuffer.cpp | |
parent | 997e745e87608467a8c5bd1f60da871743b1bbb6 (diff) | |
download | serenity-767fb01a8cf54f0760e5bbf408eb89d67239575d.zip |
AK: Report copied bytes when seekback copying from CircularBuffer
Otherwise, we have no way of determining whether our copy was truncated
by accident.
Diffstat (limited to 'AK/CircularBuffer.cpp')
-rw-r--r-- | AK/CircularBuffer.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/AK/CircularBuffer.cpp b/AK/CircularBuffer.cpp index 6d8aa4d742..884bad0f34 100644 --- a/AK/CircularBuffer.cpp +++ b/AK/CircularBuffer.cpp @@ -206,20 +206,21 @@ ErrorOr<size_t> CircularBuffer::fill_from_stream(Stream& stream) return bytes.size(); } -ErrorOr<void> CircularBuffer::copy_from_seekback(size_t distance, size_t length) +ErrorOr<size_t> CircularBuffer::copy_from_seekback(size_t distance, size_t length) { if (distance > m_seekback_limit) return Error::from_string_literal("Tried a seekback copy beyond the seekback limit"); - while (length > 0) { + auto remaining_length = length; + while (remaining_length > 0) { auto next_span = next_read_span_with_seekback(distance); if (next_span.size() == 0) break; - length -= write(next_span.trim(length)); + remaining_length -= write(next_span.trim(remaining_length)); } - return {}; + return length - remaining_length; } } |