This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 3a7d680e055bf6a5b2e539306cf1423c041b74f1 Author: wangjianyu3 <[email protected]> AuthorDate: Thu Jun 11 12:14:05 2026 +0800 include/nuttx/ring: assert ring capacity fits RING_SIZE_MAX Add a static_assert(RING_CAPACITY(buflen) <= RING_SIZE_MAX) as the first member of the ring struct in RING_DECLARE and RING_DEFINE_BMP, so an over-sized buffer is rejected at compile time instead of silently overflowing the 24-bit ring index. Centralizing the check in the macros removes the need for callers to repeat it at each ring definition site. Signed-off-by: wangjianyu3 <[email protected]> --- include/nuttx/ring.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nuttx/ring.h b/include/nuttx/ring.h index 94e9494dd76..b020df2fda9 100644 --- a/include/nuttx/ring.h +++ b/include/nuttx/ring.h @@ -224,6 +224,8 @@ #define RING_DECLARE(name, type, buflen) \ struct ring_##name##_s \ { \ + static_assert(RING_CAPACITY(buflen) <= RING_SIZE_MAX,\ + "ring capacity exceeds RING_SIZE_MAX");\ struct ring_s base; \ type buf[RING_CAPACITY(buflen)]; \ } name aligned_data(CACHELINE_SIZE)
