Skip to content

Commit 08ee8aa

Browse files
committed
Fix wrong allocation size of ringbuffer
1 parent 818ad45 commit 08ee8aa

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

ringbuffer/ringbuffer.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ typedef struct {
5656
#define RING_SIZE_MASK (unsigned) (0x0fffffff) /**< Ring size mask */
5757
#define ALIGN_FLOOR(val, align) \
5858
(typeof(val))((val) & (~((typeof(val))((align) -1))))
59+
#define ALIGN_CEIL(val, align) (ALIGN_FLOOR((val) -1, align) + (align))
5960

6061
/**
6162
* Calculate the memory size needed for a ring buffer.
@@ -80,7 +81,7 @@ ssize_t ringbuf_get_memsize(const unsigned count)
8081
return -EINVAL;
8182

8283
ssize_t sz = sizeof(ringbuf_t) + count * sizeof(void *);
83-
sz = ALIGN_FLOOR(sz, CACHE_LINE_SIZE);
84+
sz = ALIGN_CEIL(sz, CACHE_LINE_SIZE);
8485
return sz;
8586
}
8687

0 commit comments

Comments
 (0)