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

Wolfgang Denk wd at denx.de
Thu Oct 21 13:51:26 CEST 2010


Dear Joakim Tjernlund,

In message <OFD5ABFC5E.96E88C93-ONC12577C3.00406E0E-C12577C3.00408F11 at transmode.se> you wrote:
>
> > It is legal for malloc() to return NULL in case of size==0,
> > and for the sake of simplicity I recommend we do just that.
> 
> Yes, but not very useful. Glibc does not return NULL

Maybe not in the current implementation, and not on the architecture
you checked. Current doc reads: "If size is 0, then malloc() returns
either NULL, or a unique pointer value that can later be successfully
passed to free()."

Of course we could return some valid pointer like glibc does, i. e.
implement something like

	if (size == 0)
		size = 8;

or so.  Do you think that would be better?

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Horses just naturally have mohawk haircuts.


More information about the U-Boot mailing list