public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dietmar Maurer <dietmar@proxmox.com>
To: Proxmox Backup Server development discussion
	<pbs-devel@lists.proxmox.com>,
	 Maximiliano Sandoval <m.sandoval@proxmox.com>
Cc: Maximiliano Sandoval <msandoval@haya.proxmox.com>
Subject: Re: [pbs-devel] [PATCH] fix #4638: proxmox-backup-client: status: guard against div by zero
Date: Wed, 7 Jun 2023 09:40:50 +0200 (CEST)	[thread overview]
Message-ID: <1109818546.68.1686123650324@webmail.proxmox.com> (raw)
In-Reply-To: <20230606123031.3133324-1-m.sandoval@proxmox.com>

Please can you set the correct email address in git config?

Otherwise the patch looks ok for me, thanks!

> On 06/06/2023 2:30 PM CEST Maximiliano Sandoval <m.sandoval@proxmox.com> wrote:
> 
>  
> From: Maximiliano Sandoval <msandoval@haya.proxmox.com>
> 
> We throw an error if the value for total is zero.
> 
> Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
> ---
>  proxmox-backup-client/src/main.rs | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/proxmox-backup-client/src/main.rs b/proxmox-backup-client/src/main.rs
> index 55198108..5a804d95 100644
> --- a/proxmox-backup-client/src/main.rs
> +++ b/proxmox-backup-client/src/main.rs
> @@ -1590,9 +1590,12 @@ async fn status(param: Value) -> Result<Value, Error> {
>          let v = v.as_u64().unwrap();
>          let total = record["total"].as_u64().unwrap();
>          let roundup = total / 200;
> -        let per = ((v + roundup) * 100) / total;
> -        let info = format!(" ({} %)", per);
> -        Ok(format!("{} {:>8}", v, info))
> +        if let Some(per) = ((v + roundup) * 100).checked_div(total) {
> +            let info = format!(" ({} %)", per);
> +            Ok(format!("{} {:>8}", v, info))
> +        } else {
> +            bail!("Cannot render total percentage: denominator is zero");
> +        }
>      };
>  
>      let options = default_table_format_options()
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel




      reply	other threads:[~2023-06-07  7:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-06 12:30 Maximiliano Sandoval
2023-06-07  7:40 ` Dietmar Maurer [this message]

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=1109818546.68.1686123650324@webmail.proxmox.com \
    --to=dietmar@proxmox.com \
    --cc=m.sandoval@proxmox.com \
    --cc=msandoval@haya.proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal