From cdfcae4d4f4879385aecb921fc416ec452ba65df Mon Sep 17 00:00:00 2001 From: maxer137 Date: Wed, 3 Apr 2024 19:20:27 +0200 Subject: [PATCH] seq: Reverted change in is_minus_zero check I had made the mistake of not running all the tests. This is indeed needed. However, you still need to add the exponent if it's positive for 0 numbers. This way, 0 numbers (such as 0e+5) will be counted as having a width of 5. This change also removes the memory allocation needed for the previous implementation. Where the string itself would be padded with zeros on the right side. Creating large numbers this method would cause large allocations in memory. This does not seem to fix issue #6182. --- src/uu/seq/src/numberparse.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/uu/seq/src/numberparse.rs b/src/uu/seq/src/numberparse.rs index 1a3ffd6b3..0ac1f93c9 100644 --- a/src/uu/seq/src/numberparse.rs +++ b/src/uu/seq/src/numberparse.rs @@ -104,16 +104,24 @@ fn parse_exponent_no_decimal(s: &str, j: usize) -> Result 0 { + 2usize + exponent as usize + } else { + 2usize + } } else { - total.try_into().unwrap() - }; - let num_integral_digits = if x.sign() == Sign::Minus { - result + 1 - } else { - result + let total = j as i64 + exponent; + let result = if total < 1 { + 1 + } else { + total.try_into().unwrap() + }; + if x.sign() == Sign::Minus { + result + 1 + } else { + result + } }; let num_fractional_digits = if exponent < 0 { -exponent as usize } else { 0 };