qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends


From: Reimar Döffinger
Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends
Date: Sat, 5 Dec 2009 19:30:15 +0100
User-agent: Mutt/1.5.20 (2009-06-14)

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]