diff --git a/qemu-malloc.c b/qemu-malloc.c
index 295d185..aeeb78b 100644
--- a/qemu-malloc.c
+++ b/qemu-malloc.c
@@ -44,22 +44,12 @@ void qemu_free(void *ptr)

  void *qemu_malloc(size_t size)
  {
-    if (!size) {
-        abort();
-    }
-    return oom_check(malloc(size));
+    return oom_check(malloc(size ? size : 1));
  }

You might want to have a 'static uint8_t zero_length_malloc[0]' and return that instead of the magic cookie '1'. Makes the code more readable IMHO and you'll also have symbol in gdb when debugging qemu.

Even more advanced: Make zero_length_malloc page-sized and page-aligned, then munmap int, so dereferencing it actually traps.

  void *qemu_realloc(void *ptr, size_t size)
  {
+    return oom_check(realloc(ptr, size ? size : 1));

qemu_realloc(qemu_malloc(0), 42);

should better work correctly ...

Likewise qemu_free(qemu_malloc(0));

cheers,
  Gerd



Reply via email to