[Fontconfig] fontconfig: Branch 'master'

Akira TAGOH akira at tagoh.org
Thu Feb 26 18:42:38 PST 2015


On Fri, Feb 27, 2015 at 7:43 AM, Raimund Steger <rs at mytum.de> 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 at mytum.de>
> +49-179-2981632 icq 16845346           work: <rs at interface-ag.de>
>



-- 
Akira TAGOH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/fontconfig/attachments/20150227/f91c9e31/attachment.html>


More information about the Fontconfig mailing list