From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGzOm-0002Dr-2M for qemu-devel@nongnu.org; Sat, 05 Dec 2009 13:30:28 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGzOh-0002D0-FX for qemu-devel@nongnu.org; Sat, 05 Dec 2009 13:30:27 -0500 Received: from [199.232.76.173] (port=39282 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGzOh-0002Cx-Az for qemu-devel@nongnu.org; Sat, 05 Dec 2009 13:30:23 -0500 Received: from mail.gmx.net ([213.165.64.20]:37877) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1NGzOh-0005AF-86 for qemu-devel@nongnu.org; Sat, 05 Dec 2009 13:30:23 -0500 Date: Sat, 5 Dec 2009 19:30:15 +0100 From: Reimar =?iso-8859-1?Q?D=F6ffinger?= Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends Message-ID: <20091205183015.GA2311@1und1.de> References: <4B193DA5.6040507@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 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: Paul Brook , Markus Armbruster , qemu-devel@nongnu.org On Sat, Dec 05, 2009 at 08:08:27PM +0300, malc wrote: > ret = read (fd, p, 0); > if (ret != 0) err (1, "read"); > return 0; > } > eof > read$ ./a.out > a.out: read: Bad address > > Even though that linux's read(2) man page claims [1]: > > DESCRIPTION > read() attempts to read up to count bytes from file descriptor fd into > the buffer starting at buf. > > If count is zero, read() returns zero and has no other results. If > count is greater than SSIZE_MAX, the result is unspecified. > > [..snip..] > > P.S. It would be interesting to know how this code behaves under OpenBSD, with > p = malloc (0); > > [1] As does, in essence, http://www.opengroup.org/onlinepubs/7990989775/xsh/read.html Which simply means that the linux man page was based on SUSv2 which obviously was quite badly written. SUSv3 gets it right (proving along the way it is better to use the POSIX man pages, i.e. "man 3 read"). It might be good to suggest them to update the linux man page though.