[vlc-devel] [PATCH] darwin/dirs: validate rc of asprint()

Tim W. tdskywalker at gmail.com
Sun Apr 26 04:10:37 CEST 2015


On Sat, Apr 25, 2015 at 9:56 PM, Rémi Denis-Courmont <remi at remlab.net>
wrote:

> Le samedi 25 avril 2015, 09:33:17 David Fuhrmann a écrit :
> > Hello,
> >
> > > Am 25.04.2015 um 02:09 schrieb Arjun Sreedharan <arjun024 at gmail.com>:
> > >
> > > When asprintf() fails, @path is undefined.
> > >
> > > Signed-off-by: Arjun Sreedharan <arjun024 at gmail.com>
> > > ---
> > > src/darwin/dirs.c | 5 +++--
> > > 1 file changed, 3 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/src/darwin/dirs.c b/src/darwin/dirs.c
> > > index 9c34cc5..7b6cedf 100644
> > > --- a/src/darwin/dirs.c
> > > +++ b/src/darwin/dirs.c
> > > @@ -82,9 +82,10 @@ char *config_GetLibDir (void)
> > >
> > >     if (dladdr(system_Init, &info)) {
> > >
> > >         char *incompletepath = strdup(dirname( (char *)info.dli_fname
> ));
> > >         char *path = NULL;
> > >
> > > -        asprintf(&path, "%s/"PACKAGE, incompletepath);
> > > +        if(asprintf(&path, "%s/"PACKAGE, incompletepath) == -1)
> > > +            path = NULL;
> >
> > This is not needed. path is already NULL on error.
>
> Does Darwin implement the FreeBSD semantics? FreeBSD sets the pointer to
> NULL
> on error, but GNU/Linux does _not_. The function is not in any standard.
>

Yosemite man pages do say it's set to NULL, not sure about older OSXes.

----------
The asprintf() and vasprintf() functions set *ret to be a pointer to a
buffer sufficiently large to  hold the formatted string. This pointer
should be passed to free(3) to release the allocated storage when it is no
longer needed. If sufficient space cannot be allocated, asprintf() and
vasprintf() will return -1 and set ret to be a NULL pointer.
----------

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20150426/e5516689/attachment.html>


More information about the vlc-devel mailing list