* [Qemu-devel] [PATCH 2 of 5] [UPDATE] implementing qemu_reallocz
@ 2008-11-21 17:07 Stefano Stabellini
2008-11-21 18:03 ` Anthony Liguori
0 siblings, 1 reply; 2+ messages in thread
From: Stefano Stabellini @ 2008-11-21 17:07 UTC (permalink / raw)
To: qemu-devel
Adding a qemu_reallocz implementation.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
---
diff -r aceb9c1e17b1 qemu-common.h
--- a/qemu-common.h Fri Nov 21 12:41:26 2008 +0000
+++ b/qemu-common.h Fri Nov 21 14:36:45 2008 +0000
@@ -96,6 +96,7 @@
void *qemu_malloc(size_t size);
void *qemu_realloc(void *ptr, size_t size);
+void *qemu_reallocz(void *ptr, size_t size);
void *qemu_mallocz(size_t size);
void qemu_free(void *ptr);
char *qemu_strdup(const char *str);
diff -r aceb9c1e17b1 qemu-malloc.c
--- a/qemu-malloc.c Fri Nov 21 12:41:26 2008 +0000
+++ b/qemu-malloc.c Fri Nov 21 14:36:45 2008 +0000
@@ -53,6 +53,16 @@
return ptr;
}
+void *qemu_reallocz(void *ptr, size_t size)
+{
+ void *res;
+ res = realloc(ptr, size);
+ if (!res)
+ return NULL;
+ memset(res, 0, size);
+ return res;
+}
+
char *qemu_strdup(const char *str)
{
char *ptr;
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH 2 of 5] [UPDATE] implementing qemu_reallocz
2008-11-21 17:07 [Qemu-devel] [PATCH 2 of 5] [UPDATE] implementing qemu_reallocz Stefano Stabellini
@ 2008-11-21 18:03 ` Anthony Liguori
0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2008-11-21 18:03 UTC (permalink / raw)
To: qemu-devel
Stefano Stabellini wrote:
> Adding a qemu_reallocz implementation.
>
> +void *qemu_reallocz(void *ptr, size_t size)
> +{
> + void *res;
> + res = realloc(ptr, size);
> + if (!res)
> + return NULL;
> + memset(res, 0, size);
> + return res;
> +}
> +
>
I think this interface is pretty non-intuitive. My first expectation is
that only the grown region would be zero'd, not the whole thing.
In general, if you don't care about the old memory, free()/malloc()
would be a better combination. You're just doing extra work by using
realloc() here.
Regards,
Anthony Liguori
> char *qemu_strdup(const char *str)
> {
> char *ptr;
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-11-21 18:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-21 17:07 [Qemu-devel] [PATCH 2 of 5] [UPDATE] implementing qemu_reallocz Stefano Stabellini
2008-11-21 18:03 ` Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).