Skip to content

Commit 0eba3ba

Browse files
committed
Prevent stack overflow from format_general which is using precision
1 parent 4f1232a commit 0eba3ba

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

common/src/float_ops.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ pub fn format_exponent(precision: usize, magnitude: f64, case: Case) -> String {
140140
pub fn format_general(precision: usize, magnitude: f64, case: Case) -> String {
141141
match magnitude {
142142
magnitude if magnitude.is_finite() => {
143-
let r_exp = format!("{:.*e}", precision - 1, magnitude);
143+
let prec = match precision {
144+
0 => 0,
145+
_ => precision - 1,
146+
};
147+
let r_exp = format!("{:.*e}", prec, magnitude);
144148
let mut parts = r_exp.splitn(2, 'e');
145149
let base = parts.next().unwrap();
146150
let exponent = parts.next().unwrap().parse::<i64>().unwrap();

0 commit comments

Comments
 (0)