From 9f145c2a9ad730eb6d607408b9688cbf20abdde7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 9 Jun 2025 16:11:17 +0200 Subject: [PATCH] sd-event: extend comment about a flex member MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Follow-up for dbef4dd4f23517abfc73b35f0bdf004d2f8f4805. Everything that that commit says is true, but — at least for me — it wasn't obvious why the code is correct and we can do fixed-size allocations like new(struct inotify_data, 1). --- src/libsystemd/sd-event/event-source.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libsystemd/sd-event/event-source.h b/src/libsystemd/sd-event/event-source.h index d25a0958edc..7f6d5b8b50e 100644 --- a/src/libsystemd/sd-event/event-source.h +++ b/src/libsystemd/sd-event/event-source.h @@ -242,6 +242,12 @@ struct inotify_data { /* The buffer we read inotify events into */ size_t buffer_filled; /* fill level of the buffer */ - union inotify_event_buffer buffer; /* struct inotify_event in union inotify_event_buffer has flex - * array. Hence, this must be at the end. */ + union inotify_event_buffer buffer; /* We use a union to allow type-punning. One of the variants in + * the union — struct inotify_event — has a flex array, so C99 + * only allows this union to be used at the end of the structure. + * The other variant in the union defines a fixed-size buffer that + * covers the maximum size that can be used for the flex variant, + * so in fact this field has a fixed size and could be safely + * placed in the middle of the struct. Unfortunately, there is no + * mechanism to let the compiler know that. */ }; -- 2.47.3