qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0


From: Eduardo Habkost
Subject: Re: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0
Date: Tue, 19 May 2009 19:12:53 -0300
User-agent: Sup/git

(Replying only now because I wasn't CCed on the reply)

Excerpts from Jamie Lokier's message of Tue May 19 17:32:23 -0300 2009:
> Eduardo Habkost wrote:
> > Now, _that_ sounds like a really bad idea. realloc(NULL, n) is specified
> > to be equivalent to malloc(n).
> 
> No it isn't.  You can't make that substitution.
> 
> In the case where n == 0, realloc(NULL, n) is guaranteed to not
> allocate anything and return NULL, whereas malloc(n) does not
> guarantee that and in fact doesn't do that on a lot of implementations.

http://opengroup.org/onlinepubs/007908775/xsh/realloc.html

"If ptr is a null pointer, realloc() behaves like malloc() for the
specified size."

"If size is 0, either a null pointer or a unique pointer that can be
successfully passed to free() is returned."
-- 
Eduardo




reply via email to

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