Subject: bin/20259: sort(1) numeric sort incorrect with -kn
To: None <gnats-bugs@gnats.netbsd.org>
From: None <giles@nemeton.com.au>
List: netbsd-bugs
Date: 02/09/2003 18:16:09
>Number:         20259
>Category:       bin
>Synopsis:       sort(1) numeric sort incorrect with -kn
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Feb 08 23:18:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Giles Lean
>Release:        NetBSD 1.6_STABLE
>Organization:
--
Giles Lean <giles@nemeton.com.au>
>Environment:
System: NetBSD nemeton.com.au 1.6_STABLE NetBSD 1.6_STABLE (GENERIC) #0: Thu Jan 2 15:27:08 EST 2003 unpriv@nemeton.com.au:/usr/local/NetBSD/netbsd-1-6/Objdir/usr/local/NetBSD/netbsd-1-6/src/sys/arch/i386/compile/GENERIC i386
Architecture: i386
Machine: i386

$ ident /usr/bin/sort
/usr/bin/sort:
     $NetBSD: crt0.c,v 1.11 2000/06/14 22:52:49 cgd Exp $
     $NetBSD: append.c,v 1.9 2001/01/18 20:59:43 jdolecek Exp $
     $NetBSD: fields.c,v 1.9 2001/02/19 19:52:27 jdolecek Exp $
     $NetBSD: files.c,v 1.16 2001/02/19 20:50:17 jdolecek Exp $
     $NetBSD: fsort.c,v 1.20 2001/05/15 11:49:25 jdolecek Exp $
     $NetBSD: init.c,v 1.5 2001/02/19 20:50:17 jdolecek Exp $
     $NetBSD: msort.c,v 1.9 2001/01/19 10:50:31 jdolecek Exp $
     $NetBSD: sort.c,v 1.26 2001/04/30 00:25:09 ross Exp $
     $NetBSD: tmp.c,v 1.7 2001/02/19 15:45:45 jdolecek Exp $

>Description:
	sort(1) fails to sort correctly when -k and -n are used together.

>How-To-Repeat:
	# following output is incorrect
	$ echo "1\n0" | sort -k1rn
        0
        1

	# this one is correct, but I suspect by chance only
	$ echo "1\n0" | sort -k1n
	0
	1

	# without -n all is well
        $ echo "1\n0" | sort -k1r
	1
	0
	$ echo "1\n0" | sort -k1
	0
	1

	This is a simplified test case.  The original came from arch:

        # incorrect
        $ printf "0.0.hello-world--mainline--0.0\n0.1.hello-world--mainline--0.1" \
	> | sort -t. -k2rn
        0.0.hello-world--mainline--0.0
        0.1.hello-world--mainline--0.1

	# correct (using GNU sort)
        $ printf "0.0.hello-world--mainline--0.0\n0.1.hello-world--mainline--0.1" \
	> | sort -t. -k2rn
        0.1.hello-world--mainline--0.1
        0.0.hello-world--mainline--0.0

>Fix:
	
>Release-Note:
>Audit-Trail:
>Unformatted: