mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-03-31 03:29:19 +00:00
Merge pull request #2367 from gabfec/fix/term-width-oeverflow
Fix u16 mul overflow with big term width
This commit is contained in:
commit
415bf695be
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user