Skip to content
Permalink
Browse files

ring_buffer: Fix return types

Fixed return types for capacity and space get functions.
Prevents potential overflows.

Signed-off-by: Tomás Longeri <tlongeri@gmail.com>
  • Loading branch information...
tlongeri authored and carlescufi committed Jul 31, 2019
1 parent 0add925 commit e9809d530945ab60395594b5f119b229455c4199
Showing with 3 additions and 3 deletions.
  1. +3 −3 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;

0 comments on commit e9809d5

Please sign in to comment.
You can’t perform that action at this time.