[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: Gerd Hoffmann
Subject: Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
Date: Fri, 29 May 2009 12:57:50 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2

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.


reply via email to

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