dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0164-vdi-Fix-warning-from-clang.patch

5544c1
From 928865de80da6a23e6f0d4d86187c52f6c940255 Mon Sep 17 00:00:00 2001
5544c1
From: Stefan Weil <sw@weilnetz.de>
5544c1
Date: Fri, 17 Aug 2012 15:23:24 +0200
5544c1
Subject: [PATCH] vdi: Fix warning from clang
5544c1
5544c1
ccc-analyzer reports these warnings:
5544c1
5544c1
block/vdi.c:704:13: warning: Dereference of null pointer
5544c1
            bmap[i] = VDI_UNALLOCATED;
5544c1
            ^
5544c1
block/vdi.c:702:13: warning: Dereference of null pointer
5544c1
            bmap[i] = i;
5544c1
            ^
5544c1
5544c1
Moving some code into the if block fixes this.
5544c1
It also avoids calling function write with 0 bytes of data.
5544c1
5544c1
Signed-off-by: Stefan Weil <sw@weilnetz.de>
5544c1
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
5544c1
(cherry picked from commit 514f21a5d4613e495adc2e2dd48f18091454efb8)
5544c1
5544c1
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
5544c1
---
5544c1
 block/vdi.c | 25 ++++++++++++-------------
5544c1
 1 file changed, 12 insertions(+), 13 deletions(-)
5544c1
5544c1
diff --git a/block/vdi.c b/block/vdi.c
5544c1
index c4f1529..550cf58 100644
5544c1
--- a/block/vdi.c
5544c1
+++ b/block/vdi.c
5544c1
@@ -628,7 +628,6 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
5544c1
     VdiHeader header;
5544c1
     size_t i;
5544c1
     size_t bmap_size;
5544c1
-    uint32_t *bmap;
5544c1
 
5544c1
     logout("\n");
5544c1
 
5544c1
@@ -693,21 +692,21 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
5544c1
         result = -errno;
5544c1
     }
5544c1
 
5544c1
-    bmap = NULL;
5544c1
     if (bmap_size > 0) {
5544c1
-        bmap = (uint32_t *)g_malloc0(bmap_size);
5544c1
-    }
5544c1
-    for (i = 0; i < blocks; i++) {
5544c1
-        if (image_type == VDI_TYPE_STATIC) {
5544c1
-            bmap[i] = i;
5544c1
-        } else {
5544c1
-            bmap[i] = VDI_UNALLOCATED;
5544c1
+        uint32_t *bmap = g_malloc0(bmap_size);
5544c1
+        for (i = 0; i < blocks; i++) {
5544c1
+            if (image_type == VDI_TYPE_STATIC) {
5544c1
+                bmap[i] = i;
5544c1
+            } else {
5544c1
+                bmap[i] = VDI_UNALLOCATED;
5544c1
+            }
5544c1
         }
5544c1
+        if (write(fd, bmap, bmap_size) < 0) {
5544c1
+            result = -errno;
5544c1
+        }
5544c1
+        g_free(bmap);
5544c1
     }
5544c1
-    if (write(fd, bmap, bmap_size) < 0) {
5544c1
-        result = -errno;
5544c1
-    }
5544c1
-    g_free(bmap);
5544c1
+
5544c1
     if (image_type == VDI_TYPE_STATIC) {
5544c1
         if (ftruncate(fd, sizeof(header) + bmap_size + blocks * block_size)) {
5544c1
             result = -errno;
5544c1
-- 
5544c1
1.7.12.1
5544c1