[Box Backup-dev] Problem/unportability with malloc(0) on AIX
Martin Ebourne
boxbackup-dev at fluffy.co.uk
Mon Apr 24 15:06:48 BST 2006
Stefan Norlin <stefan.norlin at infoflexconnect.se> wrote:
> in my porting efforts on AIX I have comes across that
> sometime malloc is called with a size argument of 0.
>
> On Linux a pointer is returned anyway while on AIX
> NULL is returned (with errno set to EINVAL) and an
> exception is thrown.
>
> I am unsure whether the malloc(0) call is correct first
> place but the behavor is anyway different on different
> OS:s.
As much as I don't like AIX, it is entirely right here. As far as I
know C++ agrees with C on this matter, and the ISO C standard says
that an implementation shall either return a NULL pointer or a unique
pointer (which may not be dereferenced) in the case of malloc(0).
It also says that realloc(NULL, size) will work, and that free(NULL)
is safe, so the code can handle nulls ok if it wants to.
This is a bug in box, so if you can track down where it is being
allocated we can look at fixing it.
Cheers,
Martin.
More information about the Boxbackup-dev
mailing list