bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#9128: [PATCH] Fix handling of non-numeric keys with '-n'


From: Eric Blake
Subject: bug#9128: [PATCH] Fix handling of non-numeric keys with '-n'
Date: Wed, 20 Jul 2011 19:38:59 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110621 Fedora/3.1.11-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.11

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   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org





reply via email to

[Prev in Thread] Current Thread [Next in Thread]