From: Paolo Bonzini <pbonzini@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] qemu-img: Fix division by zero for zero size images
Date: Fri, 12 Oct 2012 18:56:03 +0200 [thread overview]
Message-ID: <50784BA3.9050401@redhat.com> (raw)
In-Reply-To: <1350045069-8500-2-git-send-email-kwolf@redhat.com>
Il 12/10/2012 14:31, Kevin Wolf ha scritto:
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
> 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? */
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
/me keeps this in mind for reviewing Mirek's qemu-img compare series
next prev parent reply other threads:[~2012-10-12 16:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-12 12:31 [Qemu-devel] [PATCH 0/2] qemu-img: Fix division by zero for zero size images Kevin Wolf
2012-10-12 12:31 ` [Qemu-devel] [PATCH 1/2] " Kevin Wolf
2012-10-12 16:56 ` Paolo Bonzini [this message]
2012-10-12 12:31 ` [Qemu-devel] [PATCH 2/2] qemu-iotests: Test qemu-img operation on zero size image Kevin Wolf
2012-10-12 16:57 ` Paolo Bonzini
2012-10-15 8:47 ` Kevin Wolf
2012-10-15 9:42 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50784BA3.9050401@redhat.com \
--to=pbonzini@redhat.com \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.