use qemu_malloc and friends consistently
Quoted 6 lines · ----- "Jamie Lokier
Quoted 4 lines · [email protected] 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 ...
Quoted 7 lines
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 ...
JC
Quoted 1 line
-- Jamie
Quoted 17 lines · [email protected] wrote:
Quoted 6 lines · ----- "Jamie Lokier
Quoted 4 lines · [email protected] 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 ...
Quoted 7 lines
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)).
Quoted 1 line
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_PTRvalue returned forkmalloc(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