commit 8ebdb97ea7848b5baf74ee6d9842b0a2e8a0d5fc
parent 22e3b155f4b34ab54aacda6c0c96c69780e2b587
Author: bfredl <bjorn.linse@gmail.com>
Date: Sat, 14 Jan 2023 11:34:48 +0100
fix(rbuffer): handle edge case where write_ptr has wrapped around
when using the rbuffer as a linear buffer, exactly filling the buffer
will case write_ptr to wrap around too early. For now detect this
special case.
Of course, the rbuffer should refactored to a proper ring buffer where
write_pos >= read_pos always and there is no special case for full
buffers. This will be a follow up change.
Diffstat:
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/nvim/rbuffer.c b/src/nvim/rbuffer.c
@@ -165,7 +165,8 @@ void rbuffer_consumed_compact(RBuffer *buf, size_t count)
assert(buf->read_ptr <= buf->write_ptr);
rbuffer_consumed(buf, count);
if (buf->read_ptr > buf->start_ptr) {
- assert((size_t)(buf->read_ptr - buf->write_ptr) == buf->size);
+ assert((size_t)(buf->write_ptr - buf->read_ptr) == buf->size
+ || buf->write_ptr == buf->start_ptr);
memmove(buf->start_ptr, buf->read_ptr, buf->size);
buf->read_ptr = buf->start_ptr;
buf->write_ptr = buf->read_ptr + buf->size;