[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 05/11] vdi: Fix warning from clang
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 05/11] vdi: Fix warning from clang |
Date: |
Fri, 14 Sep 2012 14:39:06 +0200 |
From: Stefan Weil <address@hidden>
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 <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
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
- [Qemu-devel] [PULL 00/11] Block patches, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 04/11] block/curl: Fix wrong free statement, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 05/11] vdi: Fix warning from clang,
Kevin Wolf <=
- [Qemu-devel] [PATCH 01/11] sheepdog: fix savevm and loadvm, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 08/11] qapi: Add SnapshotInfo and ImageInfo., Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 02/11] ATAPI: STARTSTOPUNIT only eject/load media if powercondition is 0, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 07/11] ahci: properly reset PxCMD on HBA reset, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 03/11] ide: Fix error messages from static code analysis (no real error), Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 06/11] block: fix block tray status, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 10/11] Don't require encryption password for 'qemu-img info' command, Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 09/11] qemu-img: Add json output option to the info command., Kevin Wolf, 2012/09/14
- [Qemu-devel] [PATCH 11/11] block: Don't forget to delete temporary file, Kevin Wolf, 2012/09/14
- Re: [Qemu-devel] [PULL 00/11] Block patches, Anthony Liguori, 2012/09/17