This is the mail archive of the
mailing list for the newlib project.
Re: [PATCH] Use offsetof instead of magic number in scandir()
- From: Corinna Vinschen <vinschen at redhat dot com>
- To: newlib at sourceware dot org
- Date: Thu, 28 Mar 2013 14:54:28 +0100
- Subject: Re: [PATCH] Use offsetof instead of magic number in scandir()
- References: <1364468303-7319-1-git-send-email-sebastian dot huber at embedded-brains dot de> <20130328111705 dot GI11431 at calimero dot vinschen dot de> <51542D28 dot 7020708 at embedded-brains dot de> <20130328124241 dot GK11431 at calimero dot vinschen dot de> <5154476E dot 6060604 at embedded-brains dot de>
- Reply-to: newlib at sourceware dot org
On Mar 28 14:36, Sebastian Huber wrote:
> On 03/28/2013 01:42 PM, Corinna Vinschen wrote:
> >On Mar 28 12:44, Sebastian Huber wrote:
> >>>On 03/28/2013 12:17 PM, Corinna Vinschen wrote:
> >>>> >Shouldn't we better use the upstream version as used in FreeBSD and
> >>>> >OpenBSD?
> >>>> >
> >>>> > #define DIRSIZ(dp) \
> >>>> > ((sizeof(struct dirent) - sizeof(dp)->d_name) + \
> >>>> > (((dp)->d_namlen + 1 + 3) &~ 3))
> >>>I have problems to understand this expression. What is
> >>>"sizeof(dp)->d_name"? I think this looks like a hand-crafted
> >>>offsetof variant.
> >sizeof(dp)->d_name is sizeof((dp)->d_name), but without the lexically
> >unnecessary parens. I was just thinking that using the upstream
> >version has the advnatage to use easier comparable code, given that
> >our scandir.c is the BSD version anyway.
> Ok, this makes sense. Should I use the FreeBSD version of DIRSIZ()
> including its formatting?
> It seems that the scandir() implementations diverged a bit. In
> Newlib we have this bugfix:
> commit c7ec1406e5abb6f1ec6363e1d13061934c1746e9
> Author: Jeff Johnston <firstname.lastname@example.org>
> Date: Mon Nov 24 20:42:33 2008 +0000
> 2008-11-24 Joel Sherrill <email@example.com>
> * libc/posix/scandir.c: Fix memory leaks.
> Maybe we should report this to the BSDs.
OpenBSD as well as FreeBSD have both fixed this issue, albeit slightly
different from our version.