Messages in this thread | | | Date | Fri, 15 Sep 2023 12:14:06 -0700 | From | Kees Cook <> | Subject | Re: [PATCH v3 1/2] uapi: fix __DECLARE_FLEX_ARRAY for C++ |
| |
On Tue, Sep 12, 2023 at 07:22:24PM +0300, Alexey Dobriyan wrote: > __DECLARE_FLEX_ARRAY(T, member) macro expands to > > struct { > struct {} __empty_member; > T member[]; > }; > > which is subtly wrong in C++ because sizeof(struct{}) is 1 not 0, > changing UAPI structures layouts.
Looking at this again just now, what about using a 0-length array instead of an anonymous struct?
https://godbolt.org/z/rGaxPWjef
Then we don't need an #ifdef at all...
struct { int __empty_member[0]; T member[]; };
-Kees
-- Kees Cook
| |