vdi: Fix warning from clang
PATCH 1/1 vdi: Fix warning from clang
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 <[email protected]>
--- block/vdi.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
block/vdi.c +12 -13
@@ -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 = (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 ; + } } +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;
Signature · 1 line
1.7.10
Am 17.08.2012 15:23, schrieb Stefan Weil:
Quoted 33 lines
ccc-analyzer reports these warnings:
block/vdi.c:704:13: warning: Dereference of null pointerbmap[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 <[email protected]>--- block/vdi.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)block/vdi.c +0
-1@@ -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; }
block/vdi.c static int vdi_create(const char *filename, QEMUOptionParameter *options) · line 696
Quoted 10 lines
block/vdi.c +1
-8- 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 = (uint32_t *)g_malloc0 (bmap_size);
Thanks. Removed the unnecessary cast and applied to block-next.
Kevin