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: malc
Subject: Re: [Qemu-devel] [PATCH] Permit zero-sized qemu_malloc() & friends
Date: Sun, 6 Dec 2009 13:22:14 +0300 (MSK)

On Sun, 6 Dec 2009, Markus Armbruster wrote:

> malc <address@hidden> writes:
> 

[..snip..]

> 
> read(fd, malloc(0), 0) is just fine, because read() doesn't touch the
> buffer when the size is zero.
> 

[..snip..]

Yet under linux the address is checked even for zero case.

> >
> > I don't know what a "valid pointer" in this context represents.
> 
> I can talk standardese, if you prefer :)
> 
> malloc() either returns either a null pointer or a pointer to the
> allocated space.  In either case, you must not dereference the pointer.
> 
> OpenBSD chooses to return a pointer to the allocated space.  It chooses
> to catch common ways to dereference the pointer.
> 
> Your "p = (void *)-1" is neither a null pointer nor can it point to
> allocated space on your particular system.  Hence, it cannot be a value
> of malloc() for any argument, and therefore what read() does with it on
> that particular system doesn't matter.
> 

Here, i believe, you are inventing artificial restrictions on how
malloc behaves, i don't see anything that prevents the implementor
from setting aside a range of addresses with 31st bit set as an
indicator of "zero" allocations, and then happily giving it to the
user of malloc and consumming it in free.

-- 
mailto:address@hidden




reply via email to

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