diff --git a/mm/circbuf/circbuf.c b/mm/circbuf/circbuf.c index 165a228f458..b85a029f59c 100644 --- a/mm/circbuf/circbuf.c +++ b/mm/circbuf/circbuf.c @@ -301,12 +301,12 @@ ssize_t circbuf_peekat(FAR struct circbuf_s *circ, size_t pos, DEBUGASSERT(circ); - if (!circ->size) + if (!circ->size || pos >= circ->head) { return 0; } - len = circbuf_used(circ); + len = circ->head - pos; off = pos % circ->size; if (bytes > len)