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
This commit is contained in:
parent
1add10bfbc
commit
97cf7ec4d7
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue