File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -608,9 +608,17 @@ class BufferedStream : public ModifyingStream {
608
608
609
609
// / refills the buffer with data from the source
610
610
void refill () {
611
+ // Preserve any existing unread data then append new bytes
611
612
buffer.trim ();
612
- size_t result = readExt (buffer.address (), buffer.availableForWrite ());
613
- buffer.setAvailable (result);
613
+ size_t already_available = buffer.available ();
614
+ size_t free_space = buffer.availableForWrite ();
615
+ if (free_space == 0 ) {
616
+ // Buffer full – nothing we can append
617
+ return ;
618
+ }
619
+ // Read new data directly behind existing bytes
620
+ size_t added = readExt (buffer.address () + already_available, free_space);
621
+ buffer.setAvailable (already_available + added);
614
622
}
615
623
616
624
// / refill only if not enough data
You can’t perform that action at this time.
0 commit comments