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: [PATCH] dlfcn: Avoid one-element flexible array in Dl_serinfo


On 5/24/19 1:42 AM, Florian Weimer wrote:
This changes the size of the type and is not source-code-compatible.  I
have not investigated whether the change is still reasonably safe, but
usually, wo do not make such changes.

OK, in that case I suggest adding a comment explaining the situation, since it is a bit of a sore thumb. Something like the following perhaps? Or if this problem is likely to occur elsewhere, we could package the situation up into a macro and just use the macro here.

    /* An array of dls_cnt elements, each of type Dl_serpath.  */
  #if 0
    /* With no backward-compatibility concerns we’d use the following
       C99 flexible array member.  However, as this data structure
       predates C99 it had to contain a one-element array here, and we
       don't want to change the struct's size now.  */
    Dl_serpath dls_serpath[];
  #elif defined __GNUC__
    /* Avoid an unwanted array subscript check by the compiler, while
       preserving the size of the type.  */
    __extension__ union
    {
      Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements.  */
      Dl_serpath __dls_serpath_pad[1];
    };
  #else
    Dl_serpath dls_serpath[1];
  #endif


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