src/buffer.c

changeset 1131
644f77f903b1
parent 1128
3672b89e606c
--- a/src/buffer.c	Fri Jan 17 17:41:29 2025 +0100
+++ b/src/buffer.c	Fri Jan 17 17:55:21 2025 +0100
@@ -356,9 +356,19 @@
         CxBuffer *buffer
 ) {
     size_t pos = buffer->pos;
-    buffer->pos = buffer->size;
+    size_t append_pos = buffer->size;
+    buffer->pos = append_pos;    
     size_t written = cxBufferWrite(ptr, size, nitems, buffer);
-    buffer->pos = pos;
+    // the buffer might have been flushed
+    // we must compute a possible delta for the position
+    // expected: pos = append_pos + written
+    // -> if this is not the case, there is a delta
+    size_t delta = append_pos + written*size - buffer->pos;
+    if (delta > pos) {
+        buffer->pos = 0;
+    } else {
+        buffer->pos = pos - delta;
+    }
     return written;
 }
 

mercurial