[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 15:46:06 +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 15:07, Paul Brook wrote:
The best way to find broken code is to have qemu_malloc(0) abort, and avoid
ever trying to allocate a zero size block.

Forces all call sizes where size=0 is a perfectly legal case add extra code to prevent qemu from aborting, i.e. replace

  ptr = qemu_malloc(len);


  if (len) {
    ptr = qemu_malloc(len);
  } else {
    ptr = NULL; /* make sure we don't pass garbage to qemu_free() */

If you want maximize chances of catching accidental mistakes as early as
possible then you should have malloc(0) abort, because it probably means
someone forgot tho consider the empty case.

I don't share the assumption that malloc(0) is a bug in most cases. And on the other hand the slightly different behavior might actually introduce bugs because people assume qemu_malloc() works like malloc().


reply via email to

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