mirror of
git://git.proxmox.com/git/proxmox-backup.git
synced 2025-03-05 20:58:33 +03:00
fix #4638: proxmox-backup-client: status: guard against div by zero
We throw an error if the value for total is zero. Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
This commit is contained in:
parent
73bd988c42
commit
dae0b67f1f
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user