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


* Florian Weimer:

> diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
> index 896ad6fc9b..7107b3ea9a 100644
> --- a/dlfcn/dlfcn.h
> +++ b/dlfcn/dlfcn.h
> @@ -180,7 +180,19 @@ typedef struct
>  {
>    size_t dls_size;		/* Size in bytes of the whole buffer.  */
>    unsigned int dls_cnt;		/* Number of elements in `dls_serpath'.  */
> +# ifdef __GNUC__
> +  /* The zero-length array avoids an unwanted array subscript check by
> +     the compiler, while the surrounding anonymous union preserves the
> +     historic size of the type.  At the time of writing, GNU C does
> +     not support structs with flexible array members in unions.  */
> +  __extension__ union
> +  {
> +    Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements.  */
> +    Dl_serpath __dls_serpath_pad[1];
> +  };
> +# else /* !__GNUC__ */
>    Dl_serpath dls_serpath[1];	/* Actually longer, dls_cnt elements.  */
> +# endif /* !__GNUC__ */
>  } Dl_serinfo;
>  #endif /* __USE_GNU */
>  

It turns out that GCC 2.7.2.3 treats this anonymous union as a type
declaration and ignores it.  I will try to come up with the appropriate
__GNUC_PREREQ conditional.

(Don't get the wrong idea; we do not test regularly against older GCC
versions.)

Thanks,
Florian


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