Copy the real size of struct dirent

In some platforms, d_name is defined as the flexible array member.
We may need to compute the real size for that case.
This commit is contained in:
Akira TAGOH 2015-02-26 14:08:20 +09:00
parent dd427253cc
commit 8809d1b73b
2 changed files with 10 additions and 2 deletions

View File

@ -680,6 +680,7 @@ dnl Figure out what cache format suffix to use for this architecture
AC_C_BIGENDIAN
AC_CHECK_SIZEOF([void *])
AC_CHECK_ALIGNOF([double])
AC_CHECK_ALIGNOF([void *])
dnl include the header file for workaround of miscalculating size on autoconf
dnl particularly for fat binaries

View File

@ -215,8 +215,15 @@ FcScandir (const char *dirp,
{
if (!filter || (filter) (dent))
{
p = (struct dirent *) malloc (sizeof (struct dirent));
memcpy (p, dent, sizeof (struct dirent));
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));
}
p = (struct dirent *) malloc (dentlen);
memcpy (p, dent, dentlen);
if (n >= lsize)
{
lsize += 128;