From e9809d530945ab60395594b5f119b229455c4199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Longeri?= Date: Tue, 30 Jul 2019 22:19:01 -0400 Subject: [PATCH] ring_buffer: Fix return types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed return types for capacity and space get functions. Prevents potential overflows. Signed-off-by: Tomás Longeri --- include/sys/ring_buffer.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/sys/ring_buffer.h b/include/sys/ring_buffer.h index d226ea788ab..42516f63f7f 100644 --- a/include/sys/ring_buffer.h +++ b/include/sys/ring_buffer.h @@ -173,7 +173,7 @@ __deprecated static inline void sys_ring_buf_init(struct ring_buf *buf, * * @return Ring buffer free space (in 32-bit words or bytes). */ -static inline int z_ring_buf_custom_space_get(u32_t size, u32_t head, +static inline u32_t z_ring_buf_custom_space_get(u32_t size, u32_t head, u32_t tail) { if (tail < head) { @@ -221,7 +221,7 @@ __deprecated static inline int sys_ring_buf_is_empty(struct ring_buf *buf) * * @return Ring buffer free space (in 32-bit words or bytes). */ -static inline int ring_buf_space_get(struct ring_buf *buf) +static inline u32_t ring_buf_space_get(struct ring_buf *buf) { return z_ring_buf_custom_space_get(buf->size, buf->head, buf->tail); } @@ -233,7 +233,7 @@ static inline int ring_buf_space_get(struct ring_buf *buf) * * @return Ring buffer capacity (in 32-bit words or bytes). */ -static inline int ring_buf_capacity_get(struct ring_buf *buf) +static inline u32_t ring_buf_capacity_get(struct ring_buf *buf) { /* One element is used to distinguish between empty and full state. */ return buf->size - 1;