This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: I: [PATCH] asprintf error handling fix


Ulrich Drepper <drepper@redhat.com> writes:

> "Dmitry V. Levin" <ldv@alt-linux.org> writes:
> 
> > I'm talking about already written software which rely on zeroing
> > result_ptr.
> 
> There is no such software using glibc.

 This isn't true, I was under the impression that the return value
from asprintf() would be the same as that from snprintf(). Thus the
few times I've used asprintf() I've just done...

asprintf(&str, "...", ... );
if (!str)
 goto asprintf_malloc_fail;

...the man pages I have don't mention anything about asprintf() not
having a normal *printf() return value, although the info
documentation does indicate that it is completely different.

>                                         Changing this (which is
> completely unnecessary) will create an incompatibility.  Newly
> developed code might check only for the NULL pointer value and these
> programs would then fail with older glibc versions.

 It's a completely non-standard function, if you go to older systems
or even just different systems it's more than likely just not going to
exist.
 And even if you still consider it incompatible with older glibcs
there is ample precedent for changing functions to do the right thing
(snprintf() had a much bigger API change, for example).

> > In this case no: former asprintf implementation in bad written program
> > usually results to free(unitialized_pointer), while suggested feature will
> > lead to free(0). See the difference?
> 
> Crap.  If the return value says "failed; don't use the result" you
> cannot use the pointer value.  It's that easy.  The interface is
> completely in line with other interfaces which behave the same.

 strdup(), fopen() and a bunch of other functions[1] all return a ptr or
NULL, I probably assumed and I'm sure other did/do that asprintf()
would work the same way but the return value was kept to be similar to
the other *printf() functions.

[1] I can't think of a std. function that has an int return value and
also returns a ptr value through a parameter atm.

-- 
# James Antill -- james@and.org
:0:
* ^From: .*james@and\.org
/dev/null


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]