[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/32] qemu-img: Fix division by zero for zero size
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH 01/32] qemu-img: Fix division by zero for zero size images |
Date: |
Wed, 24 Oct 2012 11:50:25 +0200 |
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
---
qemu-img.c | 23 +++++++++++++++--------
1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index f17f187..849eb41 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -674,7 +674,7 @@ static int img_convert(int argc, char **argv)
QEMUOptionParameter *out_baseimg_param;
char *options = NULL;
const char *snapshot_name = NULL;
- float local_progress;
+ float local_progress = 0;
int min_sparse = 8; /* Need at least 4k of zeros for sparse detection */
fmt = NULL;
@@ -914,8 +914,10 @@ static int img_convert(int argc, char **argv)
sector_num = 0;
nb_sectors = total_sectors;
- local_progress = (float)100 /
- (nb_sectors / MIN(nb_sectors, cluster_sectors));
+ if (nb_sectors != 0) {
+ local_progress = (float)100 /
+ (nb_sectors / MIN(nb_sectors, cluster_sectors));
+ }
for(;;) {
int64_t bs_num;
@@ -986,8 +988,10 @@ static int img_convert(int argc, char **argv)
sector_num = 0; // total number of sectors converted so far
nb_sectors = total_sectors - sector_num;
- local_progress = (float)100 /
- (nb_sectors / MIN(nb_sectors, IO_BUF_SIZE / 512));
+ if (nb_sectors != 0) {
+ local_progress = (float)100 /
+ (nb_sectors / MIN(nb_sectors, IO_BUF_SIZE / 512));
+ }
for(;;) {
nb_sectors = total_sectors - sector_num;
@@ -1585,7 +1589,7 @@ static int img_rebase(int argc, char **argv)
int n;
uint8_t * buf_old;
uint8_t * buf_new;
- float local_progress;
+ float local_progress = 0;
buf_old = qemu_blockalign(bs, IO_BUF_SIZE);
buf_new = qemu_blockalign(bs, IO_BUF_SIZE);
@@ -1594,8 +1598,11 @@ static int img_rebase(int argc, char **argv)
bdrv_get_geometry(bs_old_backing, &old_backing_num_sectors);
bdrv_get_geometry(bs_new_backing, &new_backing_num_sectors);
- local_progress = (float)100 /
- (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512));
+ if (num_sectors != 0) {
+ local_progress = (float)100 /
+ (num_sectors / MIN(num_sectors, IO_BUF_SIZE / 512));
+ }
+
for (sector = 0; sector < num_sectors; sector += n) {
/* How many sectors can we handle with the next read? */
--
1.7.6.5
- [Qemu-devel] [PULL 00/32] Block patches, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 01/32] qemu-img: Fix division by zero for zero size images,
Kevin Wolf <=
- [Qemu-devel] [PATCH 02/32] qemu-iotests: Test qemu-img operation on zero size image, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 05/32] block: make bdrv_find_backing_image compare canonical filenames, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 03/32] qmp: fix __accept() in qmp.py, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 07/32] qemu-iotests: add relative backing file tests for block-commit (040), Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 04/32] qemu-img rebase: use empty string to rebase without backing file, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 08/32] qemu-img: Add --backing-chain option to info command, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 06/32] block: in commit, determine base image from the top image, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 12/32] monitor: Allow add-fd to any specified fd set, Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 10/32] qemu-img: document 'info --backing-chain', Kevin Wolf, 2012/10/24
- [Qemu-devel] [PATCH 11/32] block: bdrv_create(): don't leak cco.filename on error, Kevin Wolf, 2012/10/24