From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHLtx-0006qq-5b for qemu-devel@nongnu.org; Sun, 06 Dec 2009 13:32:09 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHLts-0006pV-OE for qemu-devel@nongnu.org; Sun, 06 Dec 2009 13:32:08 -0500 Received: from [199.232.76.173] (port=35708 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHLts-0006pO-El for qemu-devel@nongnu.org; Sun, 06 Dec 2009 13:32:04 -0500 Received: from mail2.shareable.org ([80.68.89.115]:46559) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NHLts-0005FX-43 for qemu-devel@nongnu.org; Sun, 06 Dec 2009 13:32:04 -0500 Date: Sun, 6 Dec 2009 18:31:57 +0000 From: Jamie Lokier Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends Message-ID: <20091206183157.GA1021@shareable.org> References: <4B193DA5.6040507@codemonkey.ws> <4B1A9359.8080305@redhat.com> <4B1A9BF4.2090909@redhat.com> <4B1AE7E3.9000905@collabora.co.uk> <4B1AE8BA.7050207@redhat.com> <4B1AEBE0.4060204@collabora.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4B1AEBE0.4060204@collabora.co.uk> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ian Molton Cc: Blue Swirl , Markus Armbruster , qemu-devel@nongnu.org, Avi Kivity , Paul Brook Ian Molton wrote: > > Read the beginning of the thread. Basically it's for arrays, malloc(n * > > sizeof(x)). > > well, make sure n is not 0. Its not that hard. I dont think I've *ever* > had a situation where I wanted to pass 0 to malloc. I would like to remind everyone that sizeof(x) can be 0 too. For example, on Linux sizeof(spinlock_t) == 0 on UP. Anything where you have a bunch of structure fields which depend on compile time configuration, or where a type might be replaced by a stub empty structure, is a possible sizeof(x) == 0. > Its not that hard. The fact is there are a number of bugs in qemu where n == 0 is not checked prior to calling qemu_malloc() at the moment. None of them are "hard" to fix - they are rare cases that nobody noticed when writing them. Until we have code analysis tools checking for that, bugs of that kind will probably keep arising. -- Jamie