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 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-05-28 22:10:43 +08:00 committed by Xiang Xiao
parent 1920ff31d3
commit 33bd797bb3
1 changed files with 2 additions and 2 deletions

View File

@ -301,12 +301,12 @@ ssize_t circbuf_peekat(FAR struct circbuf_s *circ, size_t pos,
DEBUGASSERT(circ); DEBUGASSERT(circ);
if (!circ->size) if (!circ->size || pos >= circ->head)
{ {
return 0; return 0;
} }
len = circbuf_used(circ); len = circ->head - pos;
off = pos % circ->size; off = pos % circ->size;
if (bytes > len) if (bytes > len)