[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PULL 11/20] util: Use g_new() & friends where that makes
From: |
Michael Tokarev |
Subject: |
[Qemu-trivial] [PULL 11/20] util: Use g_new() & friends where that makes obvious sense |
Date: |
Thu, 11 Dec 2014 21:15:59 +0300 |
From: Markus Armbruster <address@hidden>
g_new(T, n) is neater than g_malloc(sizeof(T) * n). It's also safer,
for two reasons. One, it catches multiplication overflowing size_t.
Two, it returns T * rather than void *, which lets the compiler catch
more type errors.
This commit only touches allocations with size arguments of the form
sizeof(T).
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Michael Tokarev <address@hidden>
---
util/hbitmap.c | 4 ++--
util/iov.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/util/hbitmap.c b/util/hbitmap.c
index b3060e6..ab13971 100644
--- a/util/hbitmap.c
+++ b/util/hbitmap.c
@@ -373,7 +373,7 @@ void hbitmap_free(HBitmap *hb)
HBitmap *hbitmap_alloc(uint64_t size, int granularity)
{
- HBitmap *hb = g_malloc0(sizeof (struct HBitmap));
+ HBitmap *hb = g_new0(struct HBitmap, 1);
unsigned i;
assert(granularity >= 0 && granularity < 64);
@@ -384,7 +384,7 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity)
hb->granularity = granularity;
for (i = HBITMAP_LEVELS; i-- > 0; ) {
size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1);
- hb->levels[i] = g_malloc0(size * sizeof(unsigned long));
+ hb->levels[i] = g_new0(unsigned long, size);
}
/* We necessarily have free bits in level 0 due to the definition
diff --git a/util/iov.c b/util/iov.c
index 24566c8..2fb18e6 100644
--- a/util/iov.c
+++ b/util/iov.c
@@ -253,7 +253,7 @@ unsigned iov_copy(struct iovec *dst_iov, unsigned int
dst_iov_cnt,
void qemu_iovec_init(QEMUIOVector *qiov, int alloc_hint)
{
- qiov->iov = g_malloc(alloc_hint * sizeof(struct iovec));
+ qiov->iov = g_new(struct iovec, alloc_hint);
qiov->niov = 0;
qiov->nalloc = alloc_hint;
qiov->size = 0;
@@ -277,7 +277,7 @@ void qemu_iovec_add(QEMUIOVector *qiov, void *base, size_t
len)
if (qiov->niov == qiov->nalloc) {
qiov->nalloc = 2 * qiov->nalloc + 1;
- qiov->iov = g_realloc(qiov->iov, qiov->nalloc * sizeof(struct iovec));
+ qiov->iov = g_renew(struct iovec, qiov->iov, qiov->nalloc);
}
qiov->iov[qiov->niov].iov_base = base;
qiov->iov[qiov->niov].iov_len = len;
--
2.1.3
- [Qemu-trivial] [PULL 04/20] acpi-build: Make DPRINTF working for acpi-build, (continued)
- [Qemu-trivial] [PULL 04/20] acpi-build: Make DPRINTF working for acpi-build, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 03/20] acpi-build: adjust indention 8 -> 4 spaces, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 02/20] target-s390x: fix possible out of bounds read, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 06/20] usb: delete redundant brackets in usb_host_handle_control(), Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 15/20] qapi-schema: fix typo about change-vnc-password, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 07/20] Drop superfluous conditionals around qemu_opts_del(), Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 14/20] fw_cfg: remove superfluous blank line, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 01/20] qmp: fix typo in input-send-event examples, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 19/20] hpet: increase spelling precision, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 13/20] get_maintainer.pl: Remove the --git-chief-penguins option, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 11/20] util: Use g_new() & friends where that makes obvious sense,
Michael Tokarev <=
- [Qemu-trivial] [PULL 18/20] pflash_cfi02.c: associate "cfi.pflash02" to "Storage devices" category, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 16/20] virtio: remove useless declaration of virtio_net_init(), Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 10/20] util: Fuse g_malloc(); memset() into g_new0(), Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 12/20] configure: Replace which(1) with "has", Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 17/20] vt82c686: fix coverity warning about out-of-bounds write, Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 08/20] Drop superfluous conditionals around g_strdup(), Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 09/20] util: Drop superfluous conditionals around g_free(), Michael Tokarev, 2014/12/11
- [Qemu-trivial] [PULL 20/20] Sort include/qemu/typedefs.h, Michael Tokarev, 2014/12/11
- Re: [Qemu-trivial] [Qemu-devel] [PULL 00/20] Trivial patches for 2014-12-11, Peter Maydell, 2014/12/11