* [Qemu-devel] [PATCH] vdi: Fix warning from clang
@ 2012-08-17 13:23 Stefan Weil
2012-09-04 14:38 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Stefan Weil @ 2012-08-17 13:23 UTC (permalink / raw)
To: Kevin Wolf; +Cc: Stefan Weil, qemu-devel
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 <sw@weilnetz.de>
---
block/vdi.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/block/vdi.c b/block/vdi.c
index c4f1529..d80114a 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 = (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;
--
1.7.10
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] vdi: Fix warning from clang
2012-08-17 13:23 [Qemu-devel] [PATCH] vdi: Fix warning from clang Stefan Weil
@ 2012-09-04 14:38 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2012-09-04 14:38 UTC (permalink / raw)
To: Stefan Weil; +Cc: qemu-devel
Am 17.08.2012 15:23, schrieb Stefan Weil:
> 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 <sw@weilnetz.de>
> ---
> block/vdi.c | 25 ++++++++++++-------------
> 1 file changed, 12 insertions(+), 13 deletions(-)
>
> diff --git a/block/vdi.c b/block/vdi.c
> index c4f1529..d80114a 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 = (uint32_t *)g_malloc0(bmap_size);
Thanks. Removed the unnecessary cast and applied to block-next.
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-04 14:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-17 13:23 [Qemu-devel] [PATCH] vdi: Fix warning from clang Stefan Weil
2012-09-04 14:38 ` Kevin Wolf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.