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

Joakim Tjernlund
2010-10-23T09:23:16Z

Scott Wood <scottwood@freescale.com> wrote on 2010/10/22 19:36:33:
>
> On Fri, 22 Oct 2010 03:55:49 -0400
> Mike Frysinger <vapier@gentoo.org> wrote:
>
> > On Friday, October 22, 2010 03:37:43 Joakim Tjernlund wrote:
> > > Mike Frysinger wrote on 2010/10/22 09:20:22:
> > > > On Friday, October 22, 2010 02:10:16 Joakim Tjernlund wrote:
>
> You couldn't do this in portable code, since malloc(0) is allowed to return
> NULL, and it wouldn't be hard to work around it by checking prop->len for
> zero. But it is a use case where malloc(0) returning non-NULL is
> convenient.
>
> I don't think Joakim's suggestion of a single "impossible_ptr" is compliant,
> though -- it's supposed to be either NULL or a *unique* pointer.

Somewhat debatable but as long it is != NULL it will do.

Would be interesting to know what other libc's/OS do.

Jocke