On Thu, Sep 03, 2020 at 08:09:08AM -0600, Tracey Emery wrote:
> On Thu, Sep 03, 2020 at 02:52:49PM +0200, Robert Klein wrote:
> > Hi,
> > 
> > on lib/libc/uuid/uuid_to_string.c the return value for asprintf is
> > checked for -1 while the manpage only says "For all these functions if
> > an output or encoding error occurs, a value less than 0 is returned."
> > 
> > The patch below adjusts to code to the man page (checking for less than
> > zero).
> > 
> 
> Where in the man page does it say this?
> 

Ah, I see where it points to all returning less than zero. My search was
failing. Whoops. But, -1 is still correct for asprintf and vasprintf.

> ----
> The asprintf() and vasprintf() functions return the number of bytes that
> were output to the newly allocated string (excluding the final ‘\0’).  A
> pointer to the newly allocated string is returned in ret; it should be
> passed to free(3) to release the allocated storage when it is no longer
> needed.  If sufficient space cannot be allocated or some other error
> occurs, these functions return -1.  The value of ret in this situation is
> implementation-dependent.  On OpenBSD, ret is set to the NULL pointer,
> but other implementations may leave ret unchanged.
> ----
> 
> The check for -1 is correct.
> 
> Thanks!
> 
> > Best regards
> > Robert
> > 
> > 
> > Index: uuid_to_string.c
> > ===================================================================
> > RCS file: /cvs/src/lib/libc/uuid/uuid_to_string.c,v
> > retrieving revision 1.2
> > diff -u -p -r1.2 uuid_to_string.c
> > --- uuid_to_string.c        10 Sep 2015 18:13:46 -0000      1.2
> > +++ uuid_to_string.c        3 Sep 2020 12:40:41 -0000
> > @@ -64,6 +64,6 @@ uuid_to_string(const uuid_t *u, char **s
> >         u->clock_seq_hi_and_reserved, u->clock_seq_low, u->node[0],
> >         u->node[1], u->node[2], u->node[3], u->node[4], u->node[5]);
> >  
> > -   if (c == -1 && status != NULL)
> > +   if (c < 0 && status != NULL)
> >             *status = uuid_s_no_memory;
> >  }
> 
> -- 
> 
> Tracey Emery

-- 

Tracey Emery

Reply via email to