Commit 97cf7ec4 authored by Akira TAGOH's avatar Akira TAGOH

Rework again to copy the struct dirent

Assuming that d_name is the last member of struct dirent.
In POSIX, the maximum length of d_name is defined as NAME_MAX
or FILENAME_MAX though, that assumption may be wrong on some
platforms where defines d_name as the flexible array member
and allocate the minimum memory to store d_name.

Patch from Raimund Steger
parent 1add10bf
......@@ -215,13 +215,8 @@ FcScandir (const char *dirp,
{
if (!filter || (filter) (dent))
{
size_t dentlen = sizeof (struct dirent);
if (sizeof (struct dirent) == FcPtrToOffset (dent, dent->d_name))
{
dentlen += strlen (dent->d_name) + 1;
dentlen = ((dentlen + ALIGNOF_VOID_P - 1) & ~(ALIGNOF_VOID_P - 1));
}
size_t dentlen = FcPtrToOffset (dent, dent->d_name) + strlen (dent->d_name) + 1;
dentlen = ((dentlen + ALIGNOF_VOID_P - 1) & ~(ALIGNOF_VOID_P - 1));
p = (struct dirent *) malloc (dentlen);
memcpy (p, dent, dentlen);
if (n >= lsize)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment