From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Emilio G. Cota" <cota@braap.org>
Subject: [Qemu-devel] [PULL 11/25] qdist: use g_renew and g_new instead of g_realloc and g_malloc.
Date: Wed, 3 Aug 2016 19:04:08 +0200 [thread overview]
Message-ID: <1470243848-11763-2-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1470243848-11763-1-git-send-email-pbonzini@redhat.com>
From: "Emilio G. Cota" <cota@braap.org>
This is safer against overflow. g_renew is available in all
version of glib, while g_realloc_n is only available in 2.24.
Signed-off-by: Emilio G. Cota <cota@braap.org>
Message-Id: <1469459025-23606-3-git-send-email-cota@braap.org>
[Rewritten to use g_new/g_renew. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
util/qdist.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/util/qdist.c b/util/qdist.c
index eb2236c..e95722b 100644
--- a/util/qdist.c
+++ b/util/qdist.c
@@ -16,7 +16,7 @@
void qdist_init(struct qdist *dist)
{
- dist->entries = g_malloc(sizeof(*dist->entries));
+ dist->entries = g_new(struct qdist_entry, 1);
dist->size = 1;
dist->n = 0;
}
@@ -62,8 +62,7 @@ void qdist_add(struct qdist *dist, double x, long count)
if (unlikely(dist->n == dist->size)) {
dist->size *= 2;
- dist->entries = g_realloc(dist->entries,
- sizeof(*dist->entries) * (dist->size));
+ dist->entries = g_renew(struct qdist_entry, dist->entries, dist->size);
}
dist->n++;
entry = &dist->entries[dist->n - 1];
@@ -188,7 +187,7 @@ void qdist_bin__internal(struct qdist *to, const struct qdist *from, size_t n)
}
}
/* they're equally spaced, so copy the dist and bail out */
- to->entries = g_realloc_n(to->entries, n, sizeof(*to->entries));
+ to->entries = g_renew(struct qdist_entry, to->entries, n);
to->n = from->n;
memcpy(to->entries, from->entries, sizeof(*to->entries) * to->n);
return;
--
2.7.4
next prev parent reply other threads:[~2016-08-03 17:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-03 17:04 [Qemu-devel] [PULL v2 00/25] Misc QEMU fixes for 2016-08-02 Paolo Bonzini
2016-08-03 17:04 ` Paolo Bonzini [this message]
2016-08-04 10:19 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1470243848-11763-2-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=cota@braap.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).