Skip to content

Commit bd9f32f

Browse files
authored
numfmt: prevent panic if float precision specifier > 65535 (uutils#12600)
1 parent d296f8d commit bd9f32f

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

src/uu/numfmt/src/format.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ fn transform_to(
628628
"{:.precision$}",
629629
round_with_precision(i2, round_method, precision),
630630
)),
631-
None if is_precision_specified => {
631+
None if is_precision_specified && precision <= u16::MAX.into() => {
632632
let i2 = round_with_precision(i2, round_method, 0);
633633
localize(format!("{i2:.precision$}"))
634634
}

tests/by-util/test_numfmt.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,3 +1627,11 @@ fn test_multibyte_suffix_issue11937() {
16271627
.succeeds()
16281628
.stdout_is(" 692.00€\n");
16291629
}
1630+
1631+
#[test]
1632+
fn test_float_precision_greater_than_16bits() {
1633+
new_ucmd!()
1634+
.args(&["--to=iec", "--format=%.65536f", "1"])
1635+
.succeeds()
1636+
.stdout_is("1\n");
1637+
}

0 commit comments

Comments
 (0)