From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJPuT-0003TC-JM for qemu-devel@nongnu.org; Mon, 18 Aug 2014 12:36:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJPuN-0002ky-FA for qemu-devel@nongnu.org; Mon, 18 Aug 2014 12:35:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35719) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJPuN-0002ki-6q for qemu-devel@nongnu.org; Mon, 18 Aug 2014 12:35:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7IGZj33022196 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 18 Aug 2014 12:35:46 -0400 Message-ID: <53F22B5D.7080906@redhat.com> Date: Mon, 18 Aug 2014 18:35:41 +0200 From: Max Reitz MIME-Version: 1.0 References: <1408378243-19713-1-git-send-email-armbru@redhat.com> <1408378243-19713-2-git-send-email-armbru@redhat.com> In-Reply-To: <1408378243-19713-2-git-send-email-armbru@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 1/4] block: Use g_new() & friends where that makes obvious sense List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster , qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com On 18.08.2014 18:10, Markus Armbruster wrote: > 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 > --- > block-migration.c | 6 +++--- > block.c | 14 +++++++------- > block/archipelago.c | 6 +++--- > block/gluster.c | 8 ++++---- > block/iscsi.c | 2 +- > block/nfs.c | 2 +- > block/qcow.c | 2 +- > block/qcow2-cluster.c | 2 +- > block/qcow2-refcount.c | 8 ++++---- > block/qcow2-snapshot.c | 8 ++++---- > block/raw-posix.c | 2 +- > block/rbd.c | 4 ++-- > block/sheepdog.c | 4 ++-- > block/vdi.c | 2 +- > block/vhdx.c | 4 ++-- > block/vmdk.c | 7 +++---- > block/vvfat.c | 2 +- > blockdev-nbd.c | 2 +- > blockdev.c | 2 +- > hw/ide/ahci.c | 2 +- > qemu-io-cmds.c | 2 +- > qemu-io.c | 2 +- > 22 files changed, 46 insertions(+), 47 deletions(-) Reviewed-by: Max Reitz