From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:53474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8uGb-0000UZ-SS for qemu-devel@nongnu.org; Tue, 04 Sep 2012 10:38:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T8uGW-0007bD-Vs for qemu-devel@nongnu.org; Tue, 04 Sep 2012 10:38:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25943) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T8uGW-0007b9-OG for qemu-devel@nongnu.org; Tue, 04 Sep 2012 10:38:08 -0400 Message-ID: <5046124D.4010409@redhat.com> Date: Tue, 04 Sep 2012 16:38:05 +0200 From: Kevin Wolf MIME-Version: 1.0 References: <1345209804-24632-1-git-send-email-sw@weilnetz.de> In-Reply-To: <1345209804-24632-1-git-send-email-sw@weilnetz.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] vdi: Fix warning from clang List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: qemu-devel@nongnu.org Am 17.08.2012 15:23, schrieb Stefan Weil: > ccc-analyzer reports these warnings: > > block/vdi.c:704:13: warning: Dereference of null pointer > bmap[i] = VDI_UNALLOCATED; > ^ > block/vdi.c:702:13: warning: Dereference of null pointer > bmap[i] = i; > ^ > > Moving some code into the if block fixes this. > It also avoids calling function write with 0 bytes of data. > > Signed-off-by: Stefan Weil > --- > block/vdi.c | 25 ++++++++++++------------- > 1 file changed, 12 insertions(+), 13 deletions(-) > > diff --git a/block/vdi.c b/block/vdi.c > index c4f1529..d80114a 100644 > --- a/block/vdi.c > +++ b/block/vdi.c > @@ -628,7 +628,6 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) > VdiHeader header; > size_t i; > size_t bmap_size; > - uint32_t *bmap; > > logout("\n"); > > @@ -693,21 +692,21 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options) > result = -errno; > } > > - bmap = NULL; > if (bmap_size > 0) { > - bmap = (uint32_t *)g_malloc0(bmap_size); > - } > - for (i = 0; i < blocks; i++) { > - if (image_type == VDI_TYPE_STATIC) { > - bmap[i] = i; > - } else { > - bmap[i] = VDI_UNALLOCATED; > + uint32_t *bmap = (uint32_t *)g_malloc0(bmap_size); Thanks. Removed the unnecessary cast and applied to block-next. Kevin