Fix index out of bounds

This commit is contained in:
Ian Manske 2025-01-11 16:57:19 -08:00
parent 5d930ffcb2
commit 454bda6d90

View file

@ -580,7 +580,7 @@ impl fmt::Display for DisplayFilesize {
// fract <= bytes by nature of `%` and bytes <= EB = 10 ^ 18
// So, the longest string for the fractional portion can be 18 characters.
let buf = &mut [b'0'; 18];
let stop = precision.unwrap_or(buf.len());
let stop = precision.unwrap_or(usize::MAX).min(buf.len());
let bytes = bytes.unsigned_abs();
let mut fract = fract * 10;
let mut i = 0;