Skip to content

Commit 415bf69

Browse files
authored
Merge pull request #2367 from gabfec/fix/term-width-oeverflow
Fix u16 mul overflow with big term width
2 parents 064f057 + d87a3b6 commit 415bf69

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/term.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ pub fn progress_bar<'a>(
216216
stdout.write_all(PREFIX)?;
217217

218218
let width = term_width - WRAPPER_WIDTH;
219-
let filled = (width * progress) / total;
219+
// Use u32 to prevent the intermediate multiplication from overflowing u16
220+
let filled = (width as u32 * progress as u32) / total as u32;
221+
let filled = filled as u16;
220222

221223
stdout.queue(SetForegroundColor(Color::Green))?;
222224
for _ in 0..filled {

0 commit comments

Comments
 (0)