From: Pádraig Brady Date: Mon, 30 Dec 2024 22:48:14 +0000 (+0000) Subject: numfmt: don't require a suffix with --from=iec-i X-Git-Tag: v9.6~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6229ac946e6ee36158db1a592279671d79a9737a;p=thirdparty%2Fcoreutils.git numfmt: don't require a suffix with --from=iec-i * 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 --- diff --git a/NEWS b/NEWS index f76393506d..fff58de819 100644 --- 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. diff --git a/src/numfmt.c b/src/numfmt.c index a9f9e81c80..99c58aee11 100644 --- a/src/numfmt.c +++ b/src/numfmt.c @@ -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); diff --git a/tests/misc/numfmt.pl b/tests/misc/numfmt.pl index 94f9ec58e7..148d9d80c3 100755 --- a/tests/misc/numfmt.pl +++ b/tests/misc/numfmt.pl @@ -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"}],