mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 05:55:46 +08:00
mm/cirbuf: Fix cannot continue read when tail > head
when head=0, tail has not yet rolled back, and at this time tail>head still has data to read Signed-off-by: yintao <yintao@xiaomi.com>
This commit is contained in:
@@ -301,11 +301,16 @@ ssize_t circbuf_peekat(FAR struct circbuf_s *circ, size_t pos,
|
|||||||
|
|
||||||
DEBUGASSERT(circ);
|
DEBUGASSERT(circ);
|
||||||
|
|
||||||
if (!circ->size || pos >= circ->head)
|
if (!circ->size)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (circ->head - pos > circ->head - circ->tail)
|
||||||
|
{
|
||||||
|
pos = circ->tail;
|
||||||
|
}
|
||||||
|
|
||||||
len = circ->head - pos;
|
len = circ->head - pos;
|
||||||
off = pos % circ->size;
|
off = pos % circ->size;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user