From 09b41829a8aad8ca91db87a2f175aa2e8cbb0a75 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 27 Jul 2022 09:51:10 +0200 Subject: [PATCH] lib: os: spsc_pbuf: Fix free space calculation Fixing bug in free space calculation which was assuming 1 byte padding and not 32 bit word padding. Bug could result in the data corruption in certain scenario. Signed-off-by: Krzysztof Chruscinski --- lib/os/spsc_pbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/os/spsc_pbuf.c b/lib/os/spsc_pbuf.c index f58ad9000fd..967869fb2e8 100644 --- a/lib/os/spsc_pbuf.c +++ b/lib/os/spsc_pbuf.c @@ -184,7 +184,7 @@ int spsc_pbuf_alloc(struct spsc_pbuf *pb, uint16_t len, char **buf) } } } else { - free_space = rd_idx - wr_idx - 1; + free_space = rd_idx - wr_idx - sizeof(uint32_t); } len = MIN(len, MAX(free_space - (int32_t)LEN_SZ, 0));