[patch] vasprintf lacks proper malloc return value check

Orjan Friberg orjan.friberg at axis.com
Mon Feb 27 10:25:46 UTC 2006


Hi list,

When experimenting with a malloc function that returns NULL out of spite, I 
found that vasprintf doesn't handle that correctly when 
__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ isn't defined.  Instead, it will return 
whatever length it wanted to allocate, but the allocated string will be set to NULL.

The attached patch takes care of this, but I'm slightly unsure if it's the 
correct way to fix it because of the

   assert(rv >= -1);

line further down in the function.  That assert seems to indicate that the 
function should never fail allocating the string.  (The alternative would be to 
skip the extra return statement, and instead set rv to -1 when malloc returns 
NULL and remove the assert.)

-- 
Orjan Friberg
Axis Communications AB
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch
Url: http://lists.busybox.net/pipermail/uclibc/attachments/20060227/f2a2a1e8/attachment.diff 


More information about the uClibc mailing list