[PATCH] dirent.h: use __flexarr instead of hardcoding [1] length

Cristian Rodríguez cristian@rodriguez.im
Thu Feb 13 21:52:20 GMT 2025


On Thu, Feb 13, 2025 at 4:42 PM Etienne Brateau
<etienne.brateau@gmail.com> wrote:
>
> Hi,
> Yes I mean Coreutils 9.2 (sorry for the confusion).
>
> I tried to compile Coreutils 9.2 with gcc-14.2 on Hurd, and I got the error at line of Coreutils lib/fts.c:1463 (https://github.com/coreutils/gnulib/blob/master/lib/fts.c#L1463), because gcc detects that access to d_name[1] (https://github.com/coreutils/gnulib/blob/master/lib/fts.c#L235), and this is "invalid" because it thinks that the size of d_name is 1.
> I didn’t specified specific options to gcc, I just did `./configure && make`.
>
> I discovered afterward that, this change actually break build of Perl because, perl does `sizeof(dirent->d_name)` (https://github.com/Perl/perl5/blob/blead/sv.c#L14148). And, with this change, it doesn’t compile.
>
> Doing a `sizeof(dirent->d_name)` seems to be a widely used technique (https://codesearch.debian.net/search?q=sizeof%5B%5E%28%5D*%5C%28%5B%5E%29%5D*%5Cbd_name&literal=0)
>

Yes, it is a widespread nonstandard misuse. The relevant standards say
d_name is of unknown size.


More information about the Libc-alpha mailing list