From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M6W3l-0004jM-9z for qemu-devel@nongnu.org; Tue, 19 May 2009 16:37:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M6W3g-0004cU-G6 for qemu-devel@nongnu.org; Tue, 19 May 2009 16:37:12 -0400 Received: from [199.232.76.173] (port=55337 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M6W3g-0004cF-9Q for qemu-devel@nongnu.org; Tue, 19 May 2009 16:37:08 -0400 Received: from mail2.shareable.org ([80.68.89.115]:45474) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1M6W3f-0005oi-Qs for qemu-devel@nongnu.org; Tue, 19 May 2009 16:37:08 -0400 Date: Tue, 19 May 2009 21:37:04 +0100 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] fix qemu_malloc() error check for size==0 Message-ID: <20090519203704.GE3986@shareable.org> References: <1242678676-19439-1-git-send-email-ehabkost@redhat.com> <20090518221705.GO2079@blackpad> <8763fxvbfk.fsf@pike.pond.sub.org> <20090519140201.GB4254@blackpad> <20090519144424.GD4254@blackpad> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: malc Cc: qemu-devel@nongnu.org, Eduardo Habkost , Markus Armbruster malc wrote: > 3) Test the returned value against NULL Indeed, that makes malloc(0) a bad idea, and why GNU/Linux sensibly makes it return a non-NULL pointer, to minimise unexpected behaviour of programs. > 4) Accidentally derefence it > > And here one would get away with it on certain subset of systems. That's not in the list of reliable things, though. You mustn't accidentally dereference p[n] after calling p = malloc(n) either. -- Jamie