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.
This commit is contained in:
bfredl
2023-01-14 11:34:48 +01:00
parent 22e3b155f4
commit 8ebdb97ea7

View File

@@ -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;