Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2fd3cc

Browse files
committed
Fix panic on stat command with zero numbers
1 parent a99f137 commit a2fd3cc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

β€Žsrc/cmds/stat.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ impl Command for StatCommand {
9999
_ => continue,
100100
}
101101

102+
let checked_div = |lhs: f64, rhs: f64| if rhs == 0. { 0. } else { lhs / rhs };
102103
let count = format!("{}/{}", l.1, l.0);
103-
let pct = format!("( {:.2} %)", ((100.0 * l.1) / l.0));
104+
let pct = format!("( {:.2} %)", checked_div(100.0 * l.1, l.0));
104105
let mut line = "".to_string();
105106
line.push_str(&" ".digit(8 - (count.len() as i32)));
106107
line.push_str(&count);
@@ -109,8 +110,12 @@ impl Command for StatCommand {
109110
print!("{}", line);
110111
print!(" ");
111112

112-
let done = "β–‘".repeat(((32.00 * l.1) / l.0) as usize).bright_green();
113-
let udone = "β–‘".repeat(32 - ((32.00 * l.1) / l.0) as usize).red();
113+
let done = "β–‘"
114+
.repeat(checked_div(32.00 * l.1, l.0) as usize)
115+
.bright_green();
116+
let udone = "β–‘"
117+
.repeat(32 - checked_div(32.00 * l.1, l.0) as usize)
118+
.red();
114119
print!("{}", done);
115120
println!("{}", udone);
116121
}

0 commit comments

Comments
(0)

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /