tag 9128 notabug
thanks
On 07/20/2011 03:01 AM, Zdenek Pavlas wrote:
There's a possible BUG when using '-n' that any non-numeric key is handled
as equal to '0'. This results in unexpected behavior eg. when using '-nu'.
Thanks for the report. However, this behavior is required by POSIX:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html
-n
Restrict the sort key to an initial numeric string, consisting of
optional <blank> characters, optional minus-sign, and zero or more
digits with an optional radix character and thousands separators (as
defined in the current locale), which shall be sorted by arithmetic
value. An empty digit string shall be treated as zero. Leading zeros and
signs on zeros shall not affect ordering.
On the line "NUMBERS", the initial numeric string is empty, hence the
line is sorted with the value of 0.
+++ b/src/sort.c
@@ -1907,6 +1907,17 @@ numcompare (char const *a, char const *b)
while (blanks[to_uchar (*b)])
b++;
+ /* Put non-numeric keys before all numbers.
+ If both non-numeric, don't return 0 unless equal. */
+ if (!ISDIGIT(*a)&& *a != '-') {
Sorry, we can't take this patch, as it would violate POSIX and probably
break existing scripts that expect sort to treat non-numeric lines as
sorting identically with 0.
--
Eric Blake [email protected] +1-801-349-2682
Libvirt virtualization library http://libvirt.org