aboutsummaryrefslogtreecommitdiff
path: root/block/vmdk.c
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2014-12-04 07:28:31 +0800
committerKevin Wolf <kwolf@redhat.com>2014-12-10 10:31:21 +0100
commit73b7bcad439e0edaced05049897090cc10d84b5b (patch)
treeeca11a8b01734c6c4cc9a9ad6e804ec9261f16a0 /block/vmdk.c
parent8a3e0bc370de9274170b82f48b0393204c3fb43b (diff)
downloadqemu-73b7bcad439e0edaced05049897090cc10d84b5b.zip
qemu-73b7bcad439e0edaced05049897090cc10d84b5b.tar.gz
qemu-73b7bcad439e0edaced05049897090cc10d84b5b.tar.bz2
vmdk: Clean up descriptor file reading
Zeroing a buffer that will be filled right after is not necessary, and allocating a power of two + 1 is naughty. Suggested-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Don Koch <dkoch@verizon.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-id: 1417649314-13704-4-git-send-email-famz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vmdk.c')
-rw-r--r--block/vmdk.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/block/vmdk.c b/block/vmdk.c
index 4ee0aed..5f43226 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -557,8 +557,8 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
return NULL;
}
- size = MIN(size, 1 << 20); /* avoid unbounded allocation */
- buf = g_malloc0(size + 1);
+ size = MIN(size, (1 << 20) - 1); /* avoid unbounded allocation */
+ buf = g_malloc(size + 1);
ret = bdrv_pread(file, desc_offset, buf, size);
if (ret < 0) {
@@ -566,6 +566,7 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
g_free(buf);
return NULL;
}
+ buf[ret] = 0;
return buf;
}