This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e503f86256c481bfd439ae469235b5435100ac42 Author: yintao <[email protected]> AuthorDate: Wed Jul 5 21:47:36 2023 +0800 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 <[email protected]> --- mm/circbuf/circbuf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/circbuf/circbuf.c b/mm/circbuf/circbuf.c index b85a029f59..f9fac1fdcf 100644 --- a/mm/circbuf/circbuf.c +++ b/mm/circbuf/circbuf.c @@ -301,11 +301,16 @@ ssize_t circbuf_peekat(FAR struct circbuf_s *circ, size_t pos, DEBUGASSERT(circ); - if (!circ->size || pos >= circ->head) + if (!circ->size) { return 0; } + if (circ->head - pos > circ->head - circ->tail) + { + pos = circ->tail; + } + len = circ->head - pos; off = pos % circ->size;
