diff options
author | Markus Armbruster <armbru@redhat.com> | 2014-08-19 10:31:08 +0200 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-08-20 11:51:28 +0200 |
commit | 5839e53bbc0fec56021d758aab7610df421ed8c8 (patch) | |
tree | 1075e29349d0b56c15c6e3b33b5dbc752d806d81 /block/vhdx.c | |
parent | 302fa283789a2f9b1199c327047cfad2258a23a2 (diff) | |
download | qemu-5839e53bbc0fec56021d758aab7610df421ed8c8.zip qemu-5839e53bbc0fec56021d758aab7610df421ed8c8.tar.gz qemu-5839e53bbc0fec56021d758aab7610df421ed8c8.tar.bz2 |
block: Use g_new() & friends where that makes obvious sense
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.
Patch created with Coccinelle, with two manual changes on top:
* Add const to bdrv_iterate_format() to keep the types straight
* Convert the allocation in bdrv_drop_intermediate(), which Coccinelle
inexplicably misses
Coccinelle semantic patch:
@@
type T;
@@
-g_malloc(sizeof(T))
+g_new(T, 1)
@@
type T;
@@
-g_try_malloc(sizeof(T))
+g_try_new(T, 1)
@@
type T;
@@
-g_malloc0(sizeof(T))
+g_new0(T, 1)
@@
type T;
@@
-g_try_malloc0(sizeof(T))
+g_try_new0(T, 1)
@@
type T;
expression n;
@@
-g_malloc(sizeof(T) * (n))
+g_new(T, n)
@@
type T;
expression n;
@@
-g_try_malloc(sizeof(T) * (n))
+g_try_new(T, n)
@@
type T;
expression n;
@@
-g_malloc0(sizeof(T) * (n))
+g_new0(T, n)
@@
type T;
expression n;
@@
-g_try_malloc0(sizeof(T) * (n))
+g_try_new0(T, n)
@@
type T;
expression p, n;
@@
-g_realloc(p, sizeof(T) * (n))
+g_renew(T, p, n)
@@
type T;
expression p, n;
@@
-g_try_realloc(p, sizeof(T) * (n))
+g_try_renew(T, p, n)
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vhdx.c')
-rw-r--r-- | block/vhdx.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/block/vhdx.c b/block/vhdx.c index f666940..87c99fc 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1381,7 +1381,7 @@ static int vhdx_create_new_headers(BlockDriverState *bs, uint64_t image_size, int ret = 0; VHDXHeader *hdr = NULL; - hdr = g_malloc0(sizeof(VHDXHeader)); + hdr = g_new0(VHDXHeader, 1); hdr->signature = VHDX_HEADER_SIGNATURE; hdr->sequence_number = g_random_int(); @@ -1654,7 +1654,7 @@ static int vhdx_create_new_region_table(BlockDriverState *bs, /* Populate enough of the BDRVVHDXState to be able to use the * pre-existing BAT calculation, translation, and update functions */ - s = g_malloc0(sizeof(BDRVVHDXState)); + s = g_new0(BDRVVHDXState, 1); s->chunk_ratio = (VHDX_MAX_SECTORS_PER_BLOCK) * (uint64_t) sector_size / (uint64_t) block_size; |