mm/circbuf: update buffer head according to real length of writing

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-02-25 10:41:22 +08:00 committed by Xiang Xiao
parent 49ce1c5df7
commit 89e8409244

View File

@ -501,6 +501,7 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
FAR const void *src, size_t bytes)
{
size_t overwrite = 0;
size_t skip = 0;
size_t space;
size_t off;
@ -514,14 +515,15 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
if (bytes > circ->size)
{
src = (FAR const void *)((FAR char *)src + bytes - circ->size);
skip = bytes - circ->size;
src = (FAR const void *)((FAR char *)src + skip);
bytes = circ->size;
}
space = circbuf_space(circ);
if (bytes > space)
{
overwrite = bytes - space;
overwrite = bytes - space + skip;
}
off = circ->head % circ->size;
@ -533,7 +535,7 @@ ssize_t circbuf_overwrite(FAR struct circbuf_s *circ,
memcpy((FAR char *)circ->base + off, src, space);
memcpy(circ->base, (FAR char *)src + space, bytes - space);
circ->head += bytes;
circ->head += bytes + skip;
circ->tail += overwrite;
return overwrite;