From 949a0059e820960a14d6e171b84d43c59ccc2295 Mon Sep 17 00:00:00 2001 From: Nick Babcock Date: Tue, 17 Feb 2026 08:25:37 -0600 Subject: [PATCH] Fix panic on parsing text version triplets as f64 Amusingly, benchmarks show a 10% performance improvement with the new structure. --- src/scalar.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/scalar.rs b/src/scalar.rs index 5a02984..f000f75 100644 --- a/src/scalar.rs +++ b/src/scalar.rs @@ -212,18 +212,16 @@ fn to_f64(mut d: &[u8]) -> Result { d = rest; } else if c == b'.' { let mut total = acc; - let mut nondigit = false; if let Some((&last, fractions)) = rest.split_last() { for &x in fractions { - nondigit |= !x.is_ascii_digit(); + if !x.is_ascii_digit() { + return Err(ScalarError::AllDigits); + } + total = total.wrapping_mul(10); total = total.wrapping_add(u64::from(x - b'0')); } - if nondigit { - return Err(ScalarError::AllDigits); - } - if last.is_ascii_digit() { total = total.wrapping_mul(10); total = total.wrapping_add(u64::from(last - b'0')); @@ -475,6 +473,7 @@ mod tests { assert!(Scalar::new(b"E").to_f64().is_err()); assert!(Scalar::new(b"").to_f64().is_err()); + assert!(Scalar::new(b"1.8.3").to_f64().is_err()); } #[test]