From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCVBA-0007gG-Or for qemu-devel@nongnu.org; Fri, 14 Sep 2012 08:39:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TCVB6-0004qs-BH for qemu-devel@nongnu.org; Fri, 14 Sep 2012 08:39:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47177) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TCVB6-0004qf-2c for qemu-devel@nongnu.org; Fri, 14 Sep 2012 08:39:24 -0400 From: Kevin Wolf Date: Fri, 14 Sep 2012 14:39:06 +0200 Message-Id: <1347626352-6023-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1347626352-6023-1-git-send-email-kwolf@redhat.com> References: <1347626352-6023-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 05/11] vdi: Fix warning from clang List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: 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 Signed-off-by: Kevin Wolf --- block/vdi.c | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-) diff --git a/block/vdi.c b/block/vdi.c index c4f1529..550cf58 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 = g_malloc0(bmap_size); + for (i = 0; i < blocks; i++) { + if (image_type == VDI_TYPE_STATIC) { + bmap[i] = i; + } else { + bmap[i] = VDI_UNALLOCATED; + } } + if (write(fd, bmap, bmap_size) < 0) { + result = -errno; + } + g_free(bmap); } - if (write(fd, bmap, bmap_size) < 0) { - result = -errno; - } - g_free(bmap); + if (image_type == VDI_TYPE_STATIC) { if (ftruncate(fd, sizeof(header) + bmap_size + blocks * block_size)) { result = -errno; -- 1.7.6.5