]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
numfmt: don't require a suffix with --from=iec-i
authorPádraig Brady <P@draigBrady.com>
Mon, 30 Dec 2024 22:48:14 +0000 (22:48 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 30 Dec 2024 22:49:31 +0000 (22:49 +0000)
* src/numfmt.c (simple_strtod_human): Only look for 'i'
after detecting a suffix.
* tests/misc/numfmt.pl: Add a test case.
* NEWS: Mention the bug fix.
Reported at https://bugs.debian.org/1091758

NEWS
src/numfmt.c
tests/misc/numfmt.pl

diff --git a/NEWS b/NEWS
index f76393506d90cd1535b6b00838e890aee711d43f..fff58de8199a743dfa5f988deba41998a221bde8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   Previously it would have ignored the affinity mask on such systems.
   [bug introduced with nproc in coreutils-8.1]
 
+  numfmt --from=iec-i now works with numbers without a suffix.
+  Previously such numbers were rejected with an error.
+  [bug introduced with numfmt in coreutils-8.21]
+
   printf now diagnoses attempts to treat empty strings as numbers,
   as per POSIX. For example, "printf '%d' ''" now issues a diagnostic
   and fails instead of silently succeeding.
index a9f9e81c80fe19fc2c98d96b783b5a5fc5efef2d..99c58aee11b0787d35e79b4ffe6341e8bfa8cd50 100644 (file)
@@ -667,18 +667,17 @@ simple_strtod_human (char const *input_str,
           devmsg ("  Auto-scaling, found 'i', switching to base %d\n",
                   scale_base);
         }
+      else if (allowed_scaling == scale_IEC_I)
+        {
+          if (**endptr == 'i')
+            (*endptr)++;
+          else
+            return SSE_MISSING_I_SUFFIX;
+        }
 
       *precision = 0;  /* Reset, to select precision based on scale.  */
     }
 
-  if (allowed_scaling == scale_IEC_I)
-    {
-      if (**endptr == 'i')
-        (*endptr)++;
-      else
-        return SSE_MISSING_I_SUFFIX;
-    }
-
   long double multiplier = powerld (scale_base, power);
 
   devmsg ("  suffix power=%d^%d = %Lf\n", scale_base, power, multiplier);
index 94f9ec58e7d69ff807147503698f76b6510612dd..148d9d80c3acfcb3bf5046a6f674a14aeed146b6 100755 (executable)
@@ -41,6 +41,7 @@ my @Tests =
      ['4', '--from=auto 1K',   {OUT => "1000"}],
      ['5', '--from=auto 1Ki',  {OUT => "1024"}],
      ['5.1', '--from=iec-i 1Ki',  {OUT => "1024"}],
+     ['5.2', '--from=iec-i 1',  {OUT => "1"}],
 
      ['6', {IN_PIPE => "1234\n"},            {OUT => "1234"}],
      ['7', '--from=si', {IN_PIPE => "2K\n"}, {OUT => "2000"}],