bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The patch of glibc which allows the user to override the pfinet serv


From: Neal H. Walfield
Subject: Re: The patch of glibc which allows the user to override the pfinet server
Date: Wed, 13 Aug 2008 13:26:10 +0200
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shij┼Ź) APEL/10.6 Emacs/21.4 (i486-pc-linux-gnu) MULE/5.0 (SAKAKI)

At Wed, 13 Aug 2008 12:41:12 +0200,
zhengda wrote:
> >> +      if (__asprintf (&name, "SOCK_SERV_%d", domain) > 0)
> >> +        {
> >> +          np = getenv (name);
> >> +          __free (name);
> >> +        }
> >>     
> >
> > You need to check whether asprintf() returns an error code (-1), meaning
> > memory allocation failed, and handle it accordingly -- just like you
> > handled failure with the explicit malloc() in your original code.
> >   
> as I understand from the manual of asprintf, asprintf always returns -1 
> if there is some error.
> 
> RETURN VALUE
>        When  successful,  these  functions return the number of bytes 
> printed,
>        just like sprintf(3).  If memory allocation wasn't  possible,  
> or  some
>        other error occurs, these functions will return -1, and the 
> contents of
>        strp is undefined.

Check if the result is != -1, not > 0, which has a different meaning.

> > If asprintf() doesn't fail, the getenv() should be done unconditionally.
> >
> >   
> >> +          if (__asprintf (&name, "%s/%d", sock_servs, domain) > 0)
> >> +              np = name;

Here too.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]