From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NH3nR-0007pT-S1 for qemu-devel@nongnu.org; Sat, 05 Dec 2009 18:12:13 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NH3nN-0007mJ-1e for qemu-devel@nongnu.org; Sat, 05 Dec 2009 18:12:13 -0500 Received: from [199.232.76.173] (port=59434 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NH3nM-0007mG-SZ for qemu-devel@nongnu.org; Sat, 05 Dec 2009 18:12:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60816) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NH3nM-00022a-L5 for qemu-devel@nongnu.org; Sat, 05 Dec 2009 18:12:08 -0500 Message-ID: <4B1AE8BA.7050207@redhat.com> Date: Sun, 06 Dec 2009 01:11:54 +0200 From: Avi Kivity MIME-Version: 1.0 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> In-Reply-To: <4B1AE7E3.9000905@collabora.co.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ian Molton Cc: Blue Swirl , Paul Brook , Markus Armbruster , qemu-devel@nongnu.org On 12/06/2009 01:08 AM, Ian Molton wrote: > Avi Kivity wrote: > > >> Only if you allocate using POSIX malloc(). If you allocate using a >> function that is defined to return a valid pointer for zero length >> allocations, you're happy. >> > Wouldnt it be better to, rather than use a qemu_malloc() that is utterly > counterintuitive in that it has no way to report failure, and behaves in > ways people dont expect, to use normal malloc() and never pass it 0 ? > It's not that it doesn't have a way to report failure, it's that it doesn't fail. Do you prefer functions that fail and report it to functions that don't fail? > Seriously, who does that anyway? why call malloc when you dont want the > space? so you can use realloc? 99.99% of the time realloc() is the Wrong > Solution(tm). > Read the beginning of the thread. Basically it's for arrays, malloc(n * sizeof(x)). > stick to what people know, and LART them for misuse of it if necessary. > The LART is a crash, great. -- Do not meddle in the internals of kernels, for they are subtle and quick to panic.