[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently
From: |
Jamie Lokier |
Subject: |
Re: [Qemu-devel] [PATCH] use qemu_malloc and friends consistently |
Date: |
Tue, 2 Jun 2009 00:46:17 +0100 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
address@hidden wrote:
>
> ----- "Jamie Lokier" <address@hidden> a écrit :
>
> > address@hidden wrote:
> > > Hi Kevin,
> > >
> > > Thanks for pointing this. I guess it just sounds strange to me that
> > > somebody would want to alloc 0 bytes. But why not ...
> >
> > Something that nobody pointed out is that sometimes you can have
> > zero-length structures these days. E.g. if you have a struct
> > containing a few spinlocks in the Linux kernel, it will be zero
> > length
> > when built on UP targets. I doubt if QEMU has any such structures,
> > but it's the sort of thing that shouldn't break
> > qemu_malloc(sizeof(some_type)).
>
> This is true but the kernel API is also making a clear distinction between
> the NULL returned value for allocation error and the specific ZERO_SIZE_PTR
> value returned for kmalloc(0, XXX). Things don't get mixed ...
Ooh, smart.
That crossed my mind for qemu_malloc() too: return (void*)16, will
SEGFAULT just like NULL but is non-NULL.
-- Jamie