* 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
This also applies to the sha*sum and b2sum utilities.
[This bug was present in "the beginning".]
+ 'numfmt' no longer drops custom suffixes from numbers it cannot fully parse.
+ [bug introduced with numfmt in coreutils-8.21]
+
'timeout' will now propagate all terminating signals to the monitored command.
Previously 'timeout' could have exited and left the monitored command running.
[bug introduced with timeout in coreutils-7.0]
/* 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));
}
*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. */
['suf-18', '--suffix=Foo --to=si 7000FooF',
{ERR => "$prog: invalid suffix in input: '7000FooF'\n"},
{EXIT => '2'}],
+ ['suf-18.1', '--invalid=ignore --suffix=QWE 12q3QWE', {OUT=>"12q3QWE"}],
+ ['suf-18.2', '--invalid=abort --suffix=QWE 12q3QWE',
+ {ERR => "$prog: invalid suffix in input: '12q3'\n"},
+ {EXIT => '2'}],
# space(s) between number and suffix. Note only field 1 is used
# by default so specify the NUL delimiter to consider the whole "line".
['suf-19', "-d '' --from=si '4.0 K'", {OUT => "4000"}],