Merge "QEMU update with VENOM (CVE-2015-3456) patch" into 5.0.2
[packages/centos6/qemu.git] / 0164-vdi-Fix-warning-from-clang.patch
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
5
6 ccc-analyzer reports these warnings:
7
8 block/vdi.c:704:13: warning: Dereference of null pointer
9             bmap[i] = VDI_UNALLOCATED;
10             ^
11 block/vdi.c:702:13: warning: Dereference of null pointer
12             bmap[i] = i;
13             ^
14
15 Moving some code into the if block fixes this.
16 It also avoids calling function write with 0 bytes of data.
17
18 Signed-off-by: Stefan Weil <sw@weilnetz.de>
19 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
20 (cherry picked from commit 514f21a5d4613e495adc2e2dd48f18091454efb8)
21
22 Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
23 ---
24  block/vdi.c | 25 ++++++++++++-------------
25  1 file changed, 12 insertions(+), 13 deletions(-)
26
27 diff --git a/block/vdi.c b/block/vdi.c
28 index c4f1529..550cf58 100644
29 --- a/block/vdi.c
30 +++ b/block/vdi.c
31 @@ -628,7 +628,6 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
32      VdiHeader header;
33      size_t i;
34      size_t bmap_size;
35 -    uint32_t *bmap;
36  
37      logout("\n");
38  
39 @@ -693,21 +692,21 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
40          result = -errno;
41      }
42  
43 -    bmap = NULL;
44      if (bmap_size > 0) {
45 -        bmap = (uint32_t *)g_malloc0(bmap_size);
46 -    }
47 -    for (i = 0; i < blocks; i++) {
48 -        if (image_type == VDI_TYPE_STATIC) {
49 -            bmap[i] = i;
50 -        } else {
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) {
55 +                bmap[i] = i;
56 +            } else {
57 +                bmap[i] = VDI_UNALLOCATED;
58 +            }
59          }
60 +        if (write(fd, bmap, bmap_size) < 0) {
61 +            result = -errno;
62 +        }
63 +        g_free(bmap);
64      }
65 -    if (write(fd, bmap, bmap_size) < 0) {
66 -        result = -errno;
67 -    }
68 -    g_free(bmap);
69 +
70      if (image_type == VDI_TYPE_STATIC) {
71          if (ftruncate(fd, sizeof(header) + bmap_size + blocks * block_size)) {
72              result = -errno;
73 -- 
74 1.7.12.1
75