Commit 25ac2fde authored by Titouan Soulard's avatar Titouan Soulard

common: fix a bug with finite circular buffers

parent 13856694
......@@ -32,8 +32,15 @@ void common_circular_buffer_write(struct CommonCBBuffer *buffer, void *bytes, ui
buffer->write_counter += reduced_byte_count;
}
// Finite buffers should have a mark of where to stop
if(buffer->readable_len >= 0) buffer->readable_len += byte_count;
// Finite buffers point to the last available sample
if(buffer->readable_len >= 0) {
buffer->readable_len += byte_count;
if(buffer->readable_len > buffer->total_len) {
printf("circular_buffer: overflow, increase buffer size\n");
buffer->readable_len = 0;
}
}
}
uint32_t common_circular_buffer_read(struct CommonCBBuffer *buffer, void *bytes, uint32_t user_count) {
......@@ -54,6 +61,8 @@ uint32_t common_circular_buffer_read(struct CommonCBBuffer *buffer, void *bytes,
total_count += read_count;
}
if(buffer->readable_len >= 0) buffer->readable_len -= total_count;
return total_count;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment