Merge pull request #5788 from coolreader18/fix-prec

Fix panic with high precision
This commit is contained in:
Noa
2025-05-16 20:28:25 -05:00
committed by GitHub
2 changed files with 4 additions and 0 deletions

View File

@@ -55,6 +55,7 @@ pub fn format_fixed(precision: usize, magnitude: f64, case: Case, alternate_form
match magnitude {
magnitude if magnitude.is_finite() => {
let point = decimal_point_or_empty(precision, alternate_form);
let precision = std::cmp::min(precision, u16::MAX as usize);
format!("{magnitude:.precision$}{point}")
}
magnitude if magnitude.is_nan() => format_nan(case),

View File

@@ -259,6 +259,9 @@ mod _io {
}
fn write(&mut self, data: &[u8]) -> Option<u64> {
if data.is_empty() {
return Some(0);
}
let length = data.len();
self.cursor.write_all(data).ok()?;
Some(length as u64)