mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 20:42:47 +00:00
btstack_ring_buffer: fix corner cases for empyt/full buffer and data length == 0
This commit is contained in:
parent
346b607c48
commit
e090bc19b5
@ -84,6 +84,9 @@ int btstack_ring_buffer_write(btstack_ring_buffer_t * ring_buffer, uint8_t * dat
|
|||||||
return ERROR_CODE_MEMORY_CAPACITY_EXCEEDED;
|
return ERROR_CODE_MEMORY_CAPACITY_EXCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// simplify logic below by asserting data_length > 0
|
||||||
|
if (data_length == 0) return 0;
|
||||||
|
|
||||||
// copy first chunk
|
// copy first chunk
|
||||||
unsigned int bytes_until_end = ring_buffer->size - ring_buffer->last_written_index;
|
unsigned int bytes_until_end = ring_buffer->size - ring_buffer->last_written_index;
|
||||||
unsigned int bytes_to_copy = btstack_min(bytes_until_end, data_length);
|
unsigned int bytes_to_copy = btstack_min(bytes_until_end, data_length);
|
||||||
@ -116,6 +119,9 @@ void btstack_ring_buffer_read(btstack_ring_buffer_t * ring_buffer, uint8_t * dat
|
|||||||
data_length = btstack_min(data_length, btstack_ring_buffer_bytes_available(ring_buffer));
|
data_length = btstack_min(data_length, btstack_ring_buffer_bytes_available(ring_buffer));
|
||||||
*number_of_bytes_read = data_length;
|
*number_of_bytes_read = data_length;
|
||||||
|
|
||||||
|
// simplify logic below by asserting data_length > 0
|
||||||
|
if (data_length == 0) return;
|
||||||
|
|
||||||
// copy first chunk
|
// copy first chunk
|
||||||
unsigned int bytes_until_end = ring_buffer->size - ring_buffer->last_read_index;
|
unsigned int bytes_until_end = ring_buffer->size - ring_buffer->last_read_index;
|
||||||
unsigned int bytes_to_copy = btstack_min(bytes_until_end, data_length);
|
unsigned int bytes_to_copy = btstack_min(bytes_until_end, data_length);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user