On Fri, Feb 27, 2015 at 7:43 AM, Raimund Steger <rs@xxxxxxxx> wrote:
Maybe we could just add FcPtrToOffset(...) and strlen(dent->d_name), regardless of sizeof(struct dirent)) (i. e. on all platforms), assuming d_name is always the last member, given it's defined as variable size by POSIX?
It looks like the maximum length of d_name is defined as NAME_MAX or FILENAME_MAX in POSIX. just using them would be simple but if there are any platforms not following it, your patch looks better indeed.
Something like:
diff --git a/src/fcstat.c b/src/fcstat.c
index d2eb258..d444bf9 100644
--- a/src/fcstat.c
+++ b/src/fcstat.c
@@ -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)
Worringer Str 31 Duesseldorf 40211 DE home: <rs@xxxxxxxx>
+49-179-2981632 icq 16845346 work: <rs@xxxxxxxxxxxxxxx>
Akira TAGOH
_______________________________________________ Fontconfig mailing list Fontconfig@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/fontconfig