From: Zbigniew Jędrzejewski-Szmek Date: Sun, 5 Feb 2023 20:15:52 +0000 (+0100) Subject: sd-journal: avoid use of fake flex arrays X-Git-Tag: v253-rc3~38^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=da8587b24e64e566a68e547ff42cf44e22714bda;p=thirdparty%2Fsystemd.git sd-journal: avoid use of fake flex arrays I tried to use DECLARE_FLEX_ARRAY like the kernel does, but it does not work for anonymous structs (they cannot be declared inline), so an open-coded version is used. --- diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index b939ee1a7e9..c4ad9575888 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -376,3 +376,15 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) { (v) = UPDATE_FLAG(v, flag, b) #define FLAGS_SET(v, flags) \ ((~(v) & (flags)) == 0) + +/* Declare a flexible array usable in a union. + * This is essentially a work-around for a pointless constraint in C99 + * and might go away in some future version of the standard. + * + * See https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=3080ea5553cc909b000d1f1d964a9041962f2c5b + */ +#define DECLARE_FLEX_ARRAY(type, name) \ + struct { \ + dummy_t __empty__ ## name; \ + type name[]; \ + } diff --git a/src/libsystemd/sd-journal/journal-def.h b/src/libsystemd/sd-journal/journal-def.h index ab4880761b3..d35290d3c70 100644 --- a/src/libsystemd/sd-journal/journal-def.h +++ b/src/libsystemd/sd-journal/journal-def.h @@ -93,22 +93,28 @@ struct FieldObject FieldObject__contents; struct FieldObject__packed FieldObject__contents _packed_; assert_cc(sizeof(struct FieldObject) == sizeof(struct FieldObject__packed)); -#define EntryObject__contents { \ - ObjectHeader object; \ - le64_t seqnum; \ - le64_t realtime; \ - le64_t monotonic; \ - sd_id128_t boot_id; \ - le64_t xor_hash; \ - union { \ - struct { \ - le64_t object_offset; \ - le64_t hash; \ - } regular[0]; \ - struct { \ - le32_t object_offset; \ - } compact[0]; \ - } items; \ +#define EntryObject__contents { \ + ObjectHeader object; \ + le64_t seqnum; \ + le64_t realtime; \ + le64_t monotonic; \ + sd_id128_t boot_id; \ + le64_t xor_hash; \ + union { \ + struct { \ + dummy_t __empty__regular; \ + struct { \ + le64_t object_offset; \ + le64_t hash; \ + } regular[]; \ + }; \ + struct { \ + dummy_t __empty_compact; \ + struct { \ + le32_t object_offset; \ + } compact[]; \ + }; \ + } items; \ } struct EntryObject EntryObject__contents; @@ -129,8 +135,8 @@ struct EntryArrayObject { ObjectHeader object; le64_t next_entry_array_offset; union { - le64_t regular[0]; - le32_t compact[0]; + DECLARE_FLEX_ARRAY(le64_t, regular); + DECLARE_FLEX_ARRAY(le32_t, compact); } items; } _packed_;