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

Wolfgang Denk wd at denx.de
Thu Oct 21 14:02:39 CEST 2010


Dear Joakim Tjernlund,

In message <OF9AD66E3F.36E9C654-ONC12577C3.004134FD-C12577C3.0041A007 at transmode.se> you wrote:
>
> > 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?
> 
> Better than NULL, but best would be a ptr that will SEGV if
> you try to defer it. Not the easiest to impl., perhaps
> ~0 will do?

The pointers you get from glibc can be read and written - they don't
segfault either (and usually we cannot do this in U-Boot, as most
systems have the MMU off).

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
How many seconds are there in a year? If I tell you there are 3.155 x
10^7, you won't even try to remember it. On the other hand, who could
forget that, to within half a percent, pi seconds is  a  nanocentury.
                                               -- Tom Duff, Bell Labs


More information about the U-Boot mailing list