From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT3v-00009c-Eb for qemu-devel@nongnu.org; Mon, 18 Aug 2014 15:57:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XJT3m-0002Ur-5e for qemu-devel@nongnu.org; Mon, 18 Aug 2014 15:57:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XJT3l-0002Uh-Uw for qemu-devel@nongnu.org; Mon, 18 Aug 2014 15:57:42 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s7IJvfV3005403 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Mon, 18 Aug 2014 15:57:41 -0400 Date: Mon, 18 Aug 2014 15:57:38 -0400 From: Jeff Cody Message-ID: <20140818195738.GC2627@localhost.localdomain> References: <1408378243-19713-1-git-send-email-armbru@redhat.com> <1408378243-19713-3-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1408378243-19713-3-git-send-email-armbru@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 2/4] block: Use g_new() & friends to avoid multiplying sizes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com On Mon, Aug 18, 2014 at 06:10:41PM +0200, Markus Armbruster wrote: > g_new(T, n) is safer than g_malloc(sizeof(*v) * n) 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. > > Perhaps a conversion to g_malloc_n() would be neater in places, but > that's merely four years old, and we can't use such newfangled stuff. > > This commit only touches allocations with size arguments of the form > sizeof(T), plus two that use 4 instead of sizeof(uint32_t). We can > make the others safe by converting to g_malloc_n() when it becomes > available to us in a couple of years. > > Signed-off-by: Markus Armbruster > --- > block/bochs.c | 2 +- > block/parallels.c | 2 +- > block/qcow2-cache.c | 2 +- > block/qed-check.c | 3 +-- > block/rbd.c | 2 +- > block/sheepdog.c | 2 +- > hw/block/nvme.c | 8 ++++---- > qemu-io-cmds.c | 10 +++++----- > 8 files changed, 15 insertions(+), 16 deletions(-) > [...] Reviewed-by: Jeff Cody