summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2025-12-22 13:14:57 +0000
committerPádraig Brady <P@draigBrady.com>2025-12-22 13:17:37 +0000
commit955dfdafa22ddb42ece2c066f12ebc4af5ba7999 (patch)
tree6a1c7fd6a96ad98213448d755c02ff802e1b198e /src
parent1313c240569db9dbf5814332a05020c196334418 (diff)
downloadcoreutils-955dfdafa22ddb42ece2c066f12ebc4af5ba7999.tar.gz
coreutils-955dfdafa22ddb42ece2c066f12ebc4af5ba7999.zip
numfmt: fix dropped custom suffix when failing to parse
* src/numfmt.c (process_suffixed_number): Restore custom suffix upon failure to parse number. * tests/numfmt/numfmt.pl: Add test cases. * NEWS: Mention the bug fix. Fixes https://bugs.debian.org/1094581
Diffstat (limited to 'src')
-rw-r--r--src/numfmt.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/numfmt.c b/src/numfmt.c
index d85a881b6..fe6350111 100644
--- a/src/numfmt.c
+++ b/src/numfmt.c
@@ -1320,14 +1320,17 @@ print_padded_number (intmax_t padding)
/* Converts the TEXT number string to the requested representation,
and handles automatic suffix addition. */
-static int
+static bool
process_suffixed_number (char *text, long double *result,
size_t *precision, long int field)
{
+ char saved_suffix = '\0';
+
if (suffix)
{
if (mbs_endswith (text, suffix))
{
+ saved_suffix = *(text + strlen (text) - strlen (suffix));
*(text + strlen (text) - strlen (suffix)) = '\0';
devmsg ("trimming suffix %s\n", quote (suffix));
}
@@ -1361,7 +1364,14 @@ process_suffixed_number (char *text, long double *result,
*result = val;
- return (e == SSE_OK || e == SSE_OK_PRECISION_LOSS);
+ if (e == SSE_OK || e == SSE_OK_PRECISION_LOSS)
+ return true;
+ else
+ {
+ if (saved_suffix)
+ *(text + strlen (text)) = saved_suffix;
+ return false;
+ }
}
/* Return true if the current charset is UTF-8. */