asprintf() issue

Rich Felker dalias@libc.org
Wed May 13 17:23:00 GMT 2015


On Wed, May 13, 2015 at 12:18:11PM -0500, Archie Cobbs wrote:
> diff --git a/manual/stdio.texi b/manual/stdio.texi
> index e407170..251c2bd 100644
> --- a/manual/stdio.texi
> +++ b/manual/stdio.texi
> @@ -2551,6 +2551,8 @@ The return value is the number of characters
> allocated for the buffer, or
>  less than zero if an error occurred.  Usually this means that the buffer
>  could not be allocated.
> 
> +If an error occurs, *@var{ptr} is set to @code{NULL}.
> +
>  Here is how to use @code{asprintf} to get the same result as the
>  @code{snprintf} example, but more easily:

Unless we're going to have a new symbol version that guarantees this
behavior, I think it would make sense to document that the behavior
used to be leaving it unchanged, and that programs intended to work
with a range of glibc versions (or other implementations) should
explicitly set ptr to NULL before making the call or refrain from
inspecting it after a non-successful call.

Rich



More information about the Libc-alpha mailing list