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>
Showing
- block-migration.c 3 additions, 3 deletionsblock-migration.c
- block.c 7 additions, 7 deletionsblock.c
- block/archipelago.c 3 additions, 3 deletionsblock/archipelago.c
- block/gluster.c 4 additions, 4 deletionsblock/gluster.c
- block/iscsi.c 1 addition, 1 deletionblock/iscsi.c
- block/nfs.c 1 addition, 1 deletionblock/nfs.c
- block/qcow.c 1 addition, 1 deletionblock/qcow.c
- block/qcow2-cluster.c 1 addition, 1 deletionblock/qcow2-cluster.c
- block/qcow2-refcount.c 4 additions, 4 deletionsblock/qcow2-refcount.c
- block/qcow2-snapshot.c 4 additions, 4 deletionsblock/qcow2-snapshot.c
- block/raw-posix.c 1 addition, 1 deletionblock/raw-posix.c
- block/rbd.c 2 additions, 2 deletionsblock/rbd.c
- block/sheepdog.c 2 additions, 2 deletionsblock/sheepdog.c
- block/vdi.c 1 addition, 1 deletionblock/vdi.c
- block/vhdx.c 2 additions, 2 deletionsblock/vhdx.c
- block/vmdk.c 3 additions, 4 deletionsblock/vmdk.c
- block/vvfat.c 1 addition, 1 deletionblock/vvfat.c
- blockdev-nbd.c 1 addition, 1 deletionblockdev-nbd.c
- blockdev.c 1 addition, 1 deletionblockdev.c
- hw/ide/ahci.c 1 addition, 1 deletionhw/ide/ahci.c
Loading
Please register or sign in to comment