From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58209) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1db4km-0006IP-TZ for qemu-devel@nongnu.org; Fri, 28 Jul 2017 08:52:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1db4kl-0001nS-TU for qemu-devel@nongnu.org; Fri, 28 Jul 2017 08:52:28 -0400 Date: Fri, 28 Jul 2017 13:52:07 +0100 From: "Daniel P. Berrange" Message-ID: <20170728125207.GN31495@redhat.com> Reply-To: "Daniel P. Berrange" References: <20170728123127.27921-1-olaf@aepfle.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH] xen-disk: use g_malloc0 to fix build List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Olaf Hering , Stefano Stabellini , Anthony Perard , Kevin Wolf , Max Reitz , "open list:X86" , "open list:Block layer core" , "open list:All patches CC here" On Fri, Jul 28, 2017 at 07:43:59AM -0500, Eric Blake wrote: > On 07/28/2017 07:31 AM, Olaf Hering wrote: > > g_malloc0_n is available since glib-2.24. To allow build with older glib > > versions use the generic g_malloc0, which is already used in many other > > places in the code. > > > > Fixes commit 3284fad728 ("xen-disk: add support for multi-page shared rings") > > > > Signed-off-by: Olaf Hering > > --- > > hw/block/xen_disk.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c > > index d42ed7070d..71deec17b0 100644 > > --- a/hw/block/xen_disk.c > > +++ b/hw/block/xen_disk.c > > @@ -1232,7 +1232,7 @@ static int blk_connect(struct XenDevice *xendev) > > return -1; > > } > > > > - domids = g_malloc0_n(blkdev->nr_ring_ref, sizeof(uint32_t)); > > + domids = g_malloc0(blkdev->nr_ring_ref * sizeof(uint32_t)); > > This version is prone to multiplication overflow (well, maybe not, but > you have to audit for that). Wouldn't it be better to use: > > domids = g_new0(blkdev->nr_ring_ref, uint32_t) You mean g_new0(uint32_t, blkdev->nr_ring_ref) but yeah, g_new0 is better than g_malloc0 pretty much every time. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|