mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:42:43 +00:00 
			
		
		
		
	AK: Report copied bytes when seekback copying from CircularBuffer
Otherwise, we have no way of determining whether our copy was truncated by accident.
This commit is contained in:
		
							parent
							
								
									997e745e87
								
							
						
					
					
						commit
						767fb01a8c
					
				
					 2 changed files with 6 additions and 5 deletions
				
			
		|  | @ -206,20 +206,21 @@ ErrorOr<size_t> CircularBuffer::fill_from_stream(Stream& stream) | ||||||
|     return bytes.size(); |     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) |     if (distance > m_seekback_limit) | ||||||
|         return Error::from_string_literal("Tried a seekback copy beyond the 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); |         auto next_span = next_read_span_with_seekback(distance); | ||||||
|         if (next_span.size() == 0) |         if (next_span.size() == 0) | ||||||
|             break; |             break; | ||||||
| 
 | 
 | ||||||
|         length -= write(next_span.trim(length)); |         remaining_length -= write(next_span.trim(remaining_length)); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return {}; |     return length - remaining_length; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -33,7 +33,7 @@ public: | ||||||
|     /// before the current write pointer and allows for reading already-read data.
 |     /// before the current write pointer and allows for reading already-read data.
 | ||||||
|     ErrorOr<Bytes> read_with_seekback(Bytes bytes, size_t distance); |     ErrorOr<Bytes> read_with_seekback(Bytes bytes, size_t distance); | ||||||
| 
 | 
 | ||||||
|     ErrorOr<void> copy_from_seekback(size_t distance, size_t length); |     ErrorOr<size_t> copy_from_seekback(size_t distance, size_t length); | ||||||
| 
 | 
 | ||||||
|     [[nodiscard]] size_t empty_space() const; |     [[nodiscard]] size_t empty_space() const; | ||||||
|     [[nodiscard]] size_t used_space() const; |     [[nodiscard]] size_t used_space() const; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Tim Schumacher
						Tim Schumacher