1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2026-04-05 18:00:17 +02:00

Merge pull request #2367 from gabfec/fix/term-width-oeverflow

Fix u16 mul overflow with big term width
This commit is contained in:
Mo Bitar
2026-03-14 17:29:10 +01:00
committed by GitHub

View File

@@ -216,7 +216,9 @@ pub fn progress_bar<'a>(
stdout.write_all(PREFIX)?;
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))?;
for _ in 0..filled {