[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently

From: malc
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 15:28:14 +0400 (MSD)

On Fri, 29 May 2009, Gerd Hoffmann wrote:

> On 05/29/09 11:51, malc wrote:
> > > Having qemu_malloc(0) abort is silly.  Returning NULL or returning
> > > malloc(1) are both reasonable options.
> > 
> > Dereference of NULL is UB[1] and dereferencing result of malloc(1) will
> > just plain work.
> malloc(0) itself isn't a bug.  Dereferencing the pointer is.
> Code like this:
>   buf = qemu_malloc(len);
>   memcpy(buf, src, len);
> will work perfectly fine when called with len=0 because it will not
> dereference buf for the len=0 case.  abort() in qemu_malloc for size=0 will
> fire for no good reason.
> > P.S. So far the abort that went into qemu_malloc caught one usage of zero
> >       allocation (once again coming from qcow2).
> That was a false positive.

No actually it wasn't, the code with current and previous[1] versions of
qemu_malloc wouldn't work on AIX.

[1] But would work with qemu_malloc returning NULL or result of malloc(1)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]