Usage of Balloc in Newlib

Corinna Vinschen
Mon Nov 12 16:04:00 GMT 2012

On Nov  6 14:32, Sebastian Huber wrote:
> Hello,
> the Balloc() function can return NULL in case _calloc_r() returns
> NULL.  All users of Balloc() in Newlib don't check for a NULL
> pointer.  Is this Balloc() supposed to never fail?
> ./libc/stdlib/strtod.c:         bd = Balloc(ptr,bd0->_k);
> ./libc/stdlib/strtod.c-         Bcopy(bd, bd0);
> [...]

The code is originally taken from BSD long ago.  You'll still find it in
NetBSD, but a quick check shows that NetBSD now checks for NULL (almost)

I guess the question here is if we want to have safe code which checks
for NULL all the time, or if we want to omit the NULL checks to get
faster and smaller code.

I'm not at all opposed to the idea to add these NULL checks if somebody
creates a patch.

I think it's not only the right thing to do, but it's also not really
worth to worry about a few bytes of code size in this floating point
related code.

However, given that I could easily be wrong, it might be worth to hear
other voices...


Corinna Vinschen
Cygwin Project Co-Leader
Red Hat

More information about the Newlib mailing list