From 33bd797bb3086df71f669afae9a67ec4c303e867 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Sun, 28 May 2023 22:10:43 +0800 Subject: [PATCH] mm/circbuf: skip buffer content according position in circbuf_peekat The circbuf_peekat should copy valid content from the specfied position of buffer, so skip the area from this position to the tail. Signed-off-by: dongjiuzhu1 --- mm/circbuf/circbuf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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)