From: Zbigniew Jędrzejewski-Szmek Date: Mon, 9 Jun 2025 14:11:17 +0000 (+0200) Subject: sd-event: extend comment about a flex member X-Git-Tag: v258-rc1~186^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F37790%2Fhead;p=thirdparty%2Fsystemd.git sd-event: extend comment about a flex member 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). --- 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. */ };