[U-Boot] [PATCH] Prevent malloc with size 0
Joakim Tjernlund
joakim.tjernlund at transmode.se
Thu Oct 21 14:54:22 CEST 2010
Wolfgang Denk <wd at denx.de> wrote on 2010/10/21 14:02:39:
>
> 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).
OK, then
if (size == 0)
size = 8;
is just as good as glibc then.
A SEGV is better but you don't have to be perfect here
More information about the U-Boot
mailing list