Skip to content

Commit d87a3b6

Browse files
committed
Fix u16 mul overflow with big term width
When running rustlings in Rover IDE, term width could have a value of 2480 which causes u16 mul overflow.
1 parent 064f057 commit d87a3b6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

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)