This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ToT glibc build problem with ToT GCC


On 29/08/2019 20:17, Carlos O'Donell wrote:
> Is there a viable solution for a static allocation of a structure
> that ends in a VLA?

flexible array member should be possible to allocate with a union:

static union
{
  struct { int nbytes; char bytes[N]; } xxx;
  struct { int nbytes; char bytes[]; } replace;
} u;

then u.replace has N extra bytes allocated (and initialized to 0).

(i think you can use u.xxx and u.replace interchangeably with
a lax interpretation of the "common initial sequence" rule
http://port70.net/~nsz/c/c11/n1570.html#6.5.2.3p6 )

if you don't want to repeat the struct type definition then

static union
{
  struct foo replace;
  char xxx[sizeof(struct foo) + N];
} u;

should work (but the tail bytes are not initialized with this
ordering, the other ordering initializes u.xxx but you have
to rely on type punning when accessing u.replace which is safe
with gcc).

these should not trigger out-of-bounds warnings.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]