summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2016-07-18 19:04:45 +0200
committerPádraig Brady <P@draigBrady.com>2016-07-18 22:24:26 +0100
commit0f9fc7b3b9aee1d001ca60de1125e6e714e70ac7 (patch)
tree87b3a57b2cf165447146a9d9238a8da2cb876239 /src
parentdfbc945a562f870f6647672374c00d4f1ffb6097 (diff)
downloadcoreutils-0f9fc7b3b9aee1d001ca60de1125e6e714e70ac7.tar.xz
sort: with -h, disallow thousands separator between number and unit
* src/sort.c (traverse_raw_number): Accept thousands separator only if it is immediately followed by a digit. * tests/misc/sort-h-thousands-sep.sh: Cover the fix for this bug. Suggested by Pádraig Brady in http://bugs.gnu.org/24015
Diffstat (limited to 'src')
-rw-r--r--src/sort.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/sort.c b/src/sort.c
index 038f6aee3..079547595 100644
--- a/src/sort.c
+++ b/src/sort.c
@@ -1895,6 +1895,7 @@ traverse_raw_number (char const **number)
char const *p = *number;
unsigned char ch;
unsigned char max_digit = '\0';
+ bool ends_with_thousands_sep = false;
/* Scan to end of number.
Decimals or separators not followed by digits stop the scan.
@@ -1910,10 +1911,18 @@ traverse_raw_number (char const **number)
/* Allow to skip only one occurrence of thousands_sep to avoid finding
the unit in the next column in case thousands_sep matches as blank
and is used as column delimiter. */
- if (*p == thousands_sep)
+ ends_with_thousands_sep = (*p == thousands_sep);
+ if (ends_with_thousands_sep)
++p;
}
+ if (ends_with_thousands_sep)
+ {
+ /* thousands_sep not followed by digit is not allowed. */
+ *number = p - 2;
+ return max_digit;
+ }
+
if (ch == decimal_point)
while (ISDIGIT (ch = *p++))
if (max_digit < ch)