asprintf() issue
Michael Kerrisk (man-pages)
mtk.manpages@gmail.com
Thu May 14 13:42:00 GMT 2015
On 05/13/2015 07:12 PM, Carlos O'Donell wrote:
> On 05/13/2015 12:14 PM, Joseph Myers wrote:
>> Does anyone know of implementations that do something other than leaving
>> the value unchanged or setting it to NULL? The external specifications in
>> question are LSB and TR 24731-2:2010 (which defers to LSB), and they seem
>> to be silent on this issue.
>
> Windows lacks asprintf, Solaris lacks asprintf, HPUX lacks asprintf,
> so we have little guidance from these OSs.
Actually, it looks like Soalris does have it.
See http://docs.oracle.com/cd/E36784_01/html/E36874/asprintf-3c.html
which says:
If sufficient space cannot be allocated, the asprintf() function
returns -1 and sets ret to be a NULL pointer.
> I know of no other implementations that do something other than leave the
> value unchanged or set to NULL.
>
> My preference is that we set it to NULL. This will aid in debugging as any
> dereferences to NULL will immediately trap. Leaving the value unchanged
> could result in further manipulation of an invalid memory location and
> program corruption.
>
> This is in line with what the BSDs do, and therefore aids in porting code
> between them.
And also in line with Solaris.
> So +1 to set it to NULL.
Not that I get to vote, but +1 to the +1 ;-).
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
More information about the Libc-alpha
mailing list