Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NHaLA-0000Ko-KG for qemu-devel@nongnu.org; Mon, 07 Dec 2009 04:57:12 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NHaL6-0000Ic-QX for qemu-devel@nongnu.org; Mon, 07 Dec 2009 04:57:12 -0500 Received: from [199.232.76.173] (port=40181 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NHaL6-0000IT-IU for qemu-devel@nongnu.org; Mon, 07 Dec 2009 04:57:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50674) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NHaL4-0002pN-Gp for qemu-devel@nongnu.org; Mon, 07 Dec 2009 04:57:07 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends 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> <20091206183157.GA1021@shareable.org> Date: Mon, 07 Dec 2009 10:56:54 +0100 In-Reply-To: <20091206183157.GA1021@shareable.org> (Jamie Lokier's message of "Sun, 6 Dec 2009 18:31:57 +0000") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jamie Lokier Cc: Blue Swirl , Paul Brook , Ian Molton , qemu-devel@nongnu.org, Avi Kivity Jamie Lokier writes: > 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. Therefore, outlawing qemu_malloc(0) impacts abstract data types: given some abstract type T, about which you're not supposed to assume anything, you can't do qemu_malloc(sizeof(T)). If anybody here is into outlawing scary zeroes, types with size zero looks like another one to outlaw. >> 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. Hard or not so hard, what would "fixing" them buy us? I keep asking this question, no takers so far. > Until we have code analysis tools checking for that, bugs of that kind > will probably keep arising. Correct.