This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: asprintf() issue
- From: "Carlos O'Donell" <carlos at redhat dot com>
- To: Rich Felker <dalias at libc dot org>, Archie Cobbs <archie dot cobbs at gmail dot com>
- Cc: Szabolcs Nagy <szabolcs dot nagy at arm dot com>, Joseph Myers <joseph at codesourcery dot com>, Florian Weimer <fweimer at redhat dot com>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, Michael Kerrisk-manpages <mtk dot manpages at gmail dot com>
- Date: Wed, 13 May 2015 13:28:47 -0400
- Subject: Re: asprintf() issue
- Authentication-results: sourceware.org; auth=none
- References: <CANSoFxt-cdc-+C4u-rTENMtY4X9RpRSuv+axDswSPxbDgag8_Q at mail dot gmail dot com> <55520F8F dot 9020308 at redhat dot com> <CANSoFxvac6_uBgwzWm5q6U+GcWzzKtDtDP0BVvE4eL08zXHs5Q at mail dot gmail dot com> <5552183C dot 2070809 at redhat dot com> <CANSoFxv7uO2Niq+wVKsC9xoDYuNgqHFxJnLrkgNqfKpFwzde=Q at mail dot gmail dot com> <alpine dot DEB dot 2 dot 10 dot 1505131601320 dot 30846 at digraph dot polyomino dot org dot uk> <55537EDF dot 9070500 at arm dot com> <CANSoFxs5f-rB7ihBbgXh4CgwSgWQpW=ZsDM++u7Y-JUaU8iFnA at mail dot gmail dot com> <20150513172215 dot GZ17573 at brightrain dot aerifal dot cx>
On 05/13/2015 01:22 PM, Rich Felker wrote:
> 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.
Agreed.
I would also like to see an attempt at a test case that used setrlimit
to restrict the available address space, followed by using asprintf
on a large string. This should be semi-portable across all the supported
machines.
Cheers,
Carlos.