[U-Boot] [PATCH] Prevent malloc with size 0

Graeme Russ graeme.russ at gmail.com
Mon Apr 2 05:16:18 CEST 2012


Hi Mike,

On Mon, Apr 2, 2012 at 1:12 PM, Mike Frysinger <vapier at gentoo.org> wrote:
> On Sunday 01 April 2012 20:25:44 Graeme Russ wrote:
>> b) The code calling malloc(0) is making a perfectly legitimate assumption
>>    based on how glibc handles malloc(0)
>
> not really.  POSIX says malloc(0) is implementation defined (so it may return a
> unique address, or it may return NULL).  no userspace code assuming malloc(0)
> will return non-NULL is correct.
> -mike

Argh! Valid point - So we can basically say that it does not matter what we
do (return NULL or return a valid pointer). Because the behaviour is
implementation specific, it is up to the caller to deal with it.

Regards,

Graeme


More information about the U-Boot mailing list