Skip to contentSkip to conversation

Simplify qemu_realloc()

PATCH In review Markus Armbruster 2 participants 2 messages Dec 14, 2009 – Feb 23, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Simplify qemu_realloc()

No functional change. Bonus: looks just like qemu_malloc() now.

---
I tagged this "FOR 0.12" because I think you might want to consider it for 0.12, not because I think it must go into 0.12.

 qemu-malloc.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
qemu-malloc.c +3 -5
index 5d9e34d..6cdc5de 100644
@@ -61,12 +61,10 @@ void *qemu_malloc(size_t size)
 
 void *qemu_realloc(void *ptr, size_t size)
 {
-    if (size) {
-        return oom_check(realloc(ptr, size));
-    } else if (allow_zero_malloc()) {
-        return oom_check(realloc(ptr, size ? size : 1));
+    if (!size && !allow_zero_malloc()) {
+        abort();
     }
-    abort();
+    return oom_check(realloc(ptr, size ? size : 1));
 }
 
 void *qemu_mallocz(size_t size)
#1 lore raw
Quoted 6 lines · Markus Armbruster

No functional change. Bonus: looks just like qemu_malloc() now.

---
I tagged this "FOR 0.12" because I think you might want to consider it for 0.12, not because I think it must go into 0.12.

It's clearly too late for 0.12, but as your patch makes sense, I have committed it to HEAD.

Quoted 26 lines
 qemu-malloc.c |    8 +++-----
 1 files changed, 3 insertions(+), 5 deletions(-)
qemu-malloc.c +3 -5
index 5d9e34d..6cdc5de 100644
@@ -61,12 +61,10 @@ void *qemu_malloc(size_t size)
 
 void *qemu_realloc(void *ptr, size_t size)
 {
-    if (size) {
-        return oom_check(realloc(ptr, size));
-    } else if (allow_zero_malloc()) {
-        return oom_check(realloc(ptr, size ? size : 1));
+    if (!size && !allow_zero_malloc()) {
+        abort();
     }
-    abort();
+    return oom_check(realloc(ptr, size ? size : 1));
 }
 
 void *qemu_mallocz(size_t size)
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net