From 6229ac946e6ee36158db1a592279671d79a9737a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Mon, 30 Dec 2024 22:48:14 +0000 Subject: [PATCH] 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 Reference:https://github.com/coreutils/coreutils/commit/6229ac946e6ee36158db1a592279671d79a9737a Conflict:delete the NEWS. --- src/numfmt.c | 15 +++++++-------- tests/misc/numfmt.pl | 1 + 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/numfmt.c b/src/numfmt.c index a9f9e81c8..99c58aee1 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 94f9ec58e..148d9d80c 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"}], -- 2.43.0