<html><head></head><body><div class="gmail_quote">Le 26 juillet 2017 10:39:01 GMT+03:00, Steve Lhomme <robux4@videolabs.io> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">In those cases the parent of a payload is accessed via the container_of() macro<br />that removes the size of the containing structure of the payload pointer. This<br />size comes from offsetof() the flexible array element at the end of the parent<br />structure.<br />The compiler is supposed to treat the flexible array element has having no size<br />in the structure (except when accessed).<br />---<br /> src/misc/objects.c | 3 +++<br /> src/misc/objres.c  | 2 ++<br /> 2 files changed, 5 insertions(+)<br /><br />diff --git a/src/misc/objects.c b/src/misc/objects.c<br />index 91eebdaf20..e953e38a64 100644<br />--- a/src/misc/objects.c<br />+++ b/src/misc/objects.c<br />@@ -186,6 +186,9 @@ void *vlc_custom_create (vlc_object_t *parent, size_t length,<br />      * and zeroes the rest.<br />      */<br />     assert (length >= sizeof (vlc_object_t));<br />+    static_assert( sizeof(vlc_object_internals_t) == <br />+                   offsetof(vlc_object_internals_t, aligned_end),<br />+                  "flexible array size is not ignored" );<br /> <br />     vlc_object_internals_t *priv = malloc (sizeof (*priv) + length);<br />     if (unlikely(priv == NULL))<br />diff --git a/src/misc/objres.c b/src/misc/objres.c<br />index 1afaccb700..b9aa87f30d 100644<br />--- a/src/misc/objres.c<br />+++ b/src/misc/objres.c<br />@@ -51,6 +51,8 @@ void *vlc_objres_new(size_t size, void (*release)(void *))<br />         errno = ENOMEM;<br />         return NULL;<br />     }<br />+    static_assert( sizeof(struct vlc_res) == offsetof(struct vlc_res, payload),<br />+                   "flexible array size is not ignored" );<br /> <br />     struct vlc_res *res = malloc(sizeof (*res) + size);<br />     if (unlikely(res == NULL))</pre></blockquote></div><br clear="all">Nack. This assertion is always true. If you want to check that nobody breaks aligned_end the sensible assertion is alignof(internals) >= alignof(max_align_t). But it would be incredibly stupid and reckless for somebody to make aligned_end not the end of the structure, so that seems pointless too.<br>
-- <br>
Rémi Denis-Courmont<br>
Typed on an inconvenient virtual keyboard</body></html>