From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M6XYi-0000Im-5M for qemu-devel@nongnu.org; Tue, 19 May 2009 18:13:16 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M6XYd-0000IJ-N3 for qemu-devel@nongnu.org; Tue, 19 May 2009 18:13:15 -0400 Received: from [199.232.76.173] (port=51748 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M6XYd-0000IG-H1 for qemu-devel@nongnu.org; Tue, 19 May 2009 18:13:11 -0400 Received: from mx2.redhat.com ([66.187.237.31]:46937) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M6XYd-0007F1-4i for qemu-devel@nongnu.org; Tue, 19 May 2009 18:13:11 -0400 Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0 From: Eduardo Habkost References: <8763fxvbfk.fsf@pike.pond.sub.org> <87octpnrhr.fsf@pike.pond.sub.org> <20090519142847.GC4254@blackpad> <20090519145653.GE4254@blackpad> <20090519154317.GF4254@blackpad> <20090519203223.GC3986@shareable.org> In-Reply-To: <20090519203223.GC3986@shareable.org> Date: Tue, 19 May 2009 19:12:53 -0300 Message-Id: <1242770959-sup-998@blackpad> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jamie Lokier Cc: Markus Armbruster , Qemu Development List (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