1 From 928865de80da6a23e6f0d4d86187c52f6c940255 Mon Sep 17 00:00:00 2001
2 From: Stefan Weil <sw@weilnetz.de>
3 Date: Fri, 17 Aug 2012 15:23:24 +0200
4 Subject: [PATCH] vdi: Fix warning from clang
6 ccc-analyzer reports these warnings:
8 block/vdi.c:704:13: warning: Dereference of null pointer
9 bmap[i] = VDI_UNALLOCATED;
11 block/vdi.c:702:13: warning: Dereference of null pointer
15 Moving some code into the if block fixes this.
16 It also avoids calling function write with 0 bytes of data.
18 Signed-off-by: Stefan Weil <sw@weilnetz.de>
19 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
20 (cherry picked from commit 514f21a5d4613e495adc2e2dd48f18091454efb8)
22 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
24 block/vdi.c | 25 ++++++++++++-------------
25 1 file changed, 12 insertions(+), 13 deletions(-)
27 diff --git a/block/vdi.c b/block/vdi.c
28 index c4f1529..550cf58 100644
31 @@ -628,7 +628,6 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
39 @@ -693,21 +692,21 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
45 - bmap = (uint32_t *)g_malloc0(bmap_size);
47 - for (i = 0; i < blocks; i++) {
48 - if (image_type == VDI_TYPE_STATIC) {
51 - bmap[i] = VDI_UNALLOCATED;
52 + uint32_t *bmap = g_malloc0(bmap_size);
53 + for (i = 0; i < blocks; i++) {
54 + if (image_type == VDI_TYPE_STATIC) {
57 + bmap[i] = VDI_UNALLOCATED;
60 + if (write(fd, bmap, bmap_size) < 0) {
65 - if (write(fd, bmap, bmap_size) < 0) {
70 if (image_type == VDI_TYPE_STATIC) {
71 if (ftruncate(fd, sizeof(header) + bmap_size + blocks * block_size)) {