From 8cb70f0d12899960851f52dad5c3c45c4a21d0c0 Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Thu, 22 Jun 2023 19:56:29 +0800 Subject: [PATCH] ringbuf: Fix ordering of StaticRingbuffer_t When building on linux/host compilers (e.g., GCC), the compiler may add padding depending on the size and order of the member types. This commit fixes the ordering or the StaticRingbuffer_t such that it matches the internal Ringbuffer_t. The "_Static_assert" is always enabled for all compilers. Closes https://github.com/espressif/esp-idf/issues/11726 --- components/esp_ringbuf/include/freertos/ringbuf.h | 4 ++-- components/esp_ringbuf/ringbuf.c | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/components/esp_ringbuf/include/freertos/ringbuf.h b/components/esp_ringbuf/include/freertos/ringbuf.h index 9a2ee166e2e4..64d7365e7971 100644 --- a/components/esp_ringbuf/include/freertos/ringbuf.h +++ b/components/esp_ringbuf/include/freertos/ringbuf.h @@ -57,8 +57,8 @@ typedef struct xSTATIC_RINGBUFFER { /** @cond */ //Doxygen command to hide this structure from API Reference size_t xDummy1[2]; UBaseType_t uxDummy2; - BaseType_t xDummy3; - void *pvDummy4[11]; + void *pvDummy3[11]; + BaseType_t xDummy4; StaticList_t xDummy5[2]; void * pvDummy6; portMUX_TYPE muxDummy; diff --git a/components/esp_ringbuf/ringbuf.c b/components/esp_ringbuf/ringbuf.c index 0f9ab40bdc44..0f90d07a9bbd 100644 --- a/components/esp_ringbuf/ringbuf.c +++ b/components/esp_ringbuf/ringbuf.c @@ -73,9 +73,7 @@ typedef struct RingbufferDefinition { portMUX_TYPE mux; //Spinlock required for SMP } Ringbuffer_t; -#if __GNUC_PREREQ(4, 6) _Static_assert(sizeof(StaticRingbuffer_t) == sizeof(Ringbuffer_t), "StaticRingbuffer_t != Ringbuffer_t"); -#endif // ------------------------------------------------ Forward Declares ---------------------------------------------------