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.
This commit is contained in:
Gabriel Feceoru 2026-03-14 16:26:22 +01:00
parent 064f057b10
commit d87a3b6ca5

View File

@ -216,7 +216,9 @@ pub fn progress_bar<'a>(
stdout.write_all(PREFIX)?; stdout.write_all(PREFIX)?;
let width = term_width - WRAPPER_WIDTH; let width = term_width - WRAPPER_WIDTH;
let filled = (width * progress) / total; // Use u32 to prevent the intermediate multiplication from overflowing u16
let filled = (width as u32 * progress as u32) / total as u32;
let filled = filled as u16;
stdout.queue(SetForegroundColor(Color::Green))?; stdout.queue(SetForegroundColor(Color::Green))?;
for _ in 0..filled { for _ in 0..filled {