[Fontconfig] fontconfig: Branch 'master'

Raimund Steger rs at mytum.de
Thu Feb 26 14:43:06 PST 2015


Hm, there is still a glitch.
d_name is char[1] on Solaris; sizeof(struct dirent) is 20 (with a 32-bit 
memory model); FcPtrToOffset(dent,dent->d_name) is 18. So this test will 
never be true:

> +
> +	    if (sizeof (struct dirent) == FcPtrToOffset (dent, dent->d_name))
> +	    {

Whether one can be sure of the char[1] thing on platforms where it's not 
... well, a lot longer? I don't know. I feel like this would be taking 
chances.

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? 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 at mytum.de>
+49-179-2981632 icq 16845346           work: <rs at interface-ag.de>


More information about the Fontconfig mailing list