[vlc-devel] [PATCH] vlc_list: fix -Wmissing-braces warning

Alexandre Janniaux ajanni at videolabs.io
Tue Feb 16 12:59:10 UTC 2021


max_align_t type is implementation-specified and thus can be requested
to be initialized with braces or not. Since the value of

    alignof(union{ max_align_t; T; })

is always equal to alignof(max_align_t), uses an union with another
type that can be initialized with { 0 }. Initialize the union as-is will
initialize the first field, so won't trigger the warning.

It still uses an initializer, not breaking the change made in previous
commit c4f0f96452453c5744b93acea4c4f939161225c3.
---
 include/vlc_list.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/vlc_list.h b/include/vlc_list.h
index 4b29fc757d..a2b2628108 100644
--- a/include/vlc_list.h
+++ b/include/vlc_list.h
@@ -233,8 +233,11 @@ static inline void vlc_list_it_next(struct vlc_list_it *restrict it)
 #define vlc_list_entry_aligned_size(p) \
     ((sizeof (*(p)) + sizeof (max_align_t) - 1) / sizeof (max_align_t))
 
+#define vlc_list_entry_dummy_zero(p_size) \
+    (union{ char b; max_align_t a; }[(p_size)]){ { 0 } }
+
 #define vlc_list_entry_dummy(p) \
-    (0 ? (p) : ((void *)(&(max_align_t[vlc_list_entry_aligned_size(p)]){0})))
+    (0 ? (p) : ((void *)( &(vlc_list_entry_dummy_zero(vlc_list_entry_aligned_size(p))) )) )
 
 #define vlc_list_offset_p(p, member) \
     ((p) = vlc_list_entry_dummy(p), (char *)(&(p)->member) - (char *)(p))
-- 
2.30.1



More information about the vlc-devel mailing list