Johannes Schindelin <Johannes.Schindelin@xxxxxx> writes: >> > [XSI][Option Start] >> > ino_t d_ino File serial number. >> > [Option End] >> > char d_name[] Filename string of entry. >> > >> > You will notice that not even `d_type` is guaranteed. >> >> I am reasonably sure that the code (without Elijah's patches anyway) >> takes the possibility of missing d_type into account already. >> >> Doesn't the above mean d_name[] has to be an in-place array of some >> size (i.e. even a flex-array is OK)? It does not look to me that it >> allows for it to be a pointer pointing at elsewhere (possibly on >> heap), which may be asking for trouble. > > You are right, of course. > > ... > > Is this compliant with POSIX? I guess not. Does it work? Yes, it does. I actually would not throw it into "it works" category. The obvious implication is that a program like this: static struct dirent *fabricate(const char *name) { /* over-allocate as we do not know how long the d_name[] is */ struct dirent *ent = calloc(1, sizeof(*ent) + strlen(name) + 1); strcpy(ent->d_name, name); return ent; } static void show_name(const struct dirent *ent) { printf("%s\n", ent->d_name); } int main(int ac, char **av) { struct dirent *mine = fabricate("mine"); show_name(mine); free(mine); return 0; } would be broken if you do not have d_name as an array. I would not be surprised if the segfaults you saw with Elijah's series all were caused by your d_name not being an array, and if that is the case, I'd rather see it fixed on your end than fixes withdrawn. Thanks.