Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 20 Feb 2006 01:46:41 +0900 (JST)
From:      Kazuaki Oda <ybbkaz@yahoo.co.jp>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   gnu/93566: [patch] sort(1): numeric sort is broken on multi-byte locales
Message-ID:  <200602191646.k1JGkfFH009260@eyes.violasystem.net>
Resent-Message-ID: <200602191650.k1JGo3Dq011758@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         93566
>Category:       gnu
>Synopsis:       [patch] sort(1): numeric sort is broken on multi-byte locales
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Feb 19 16:50:03 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Kazuaki Oda
>Release:        FreeBSD 6.1-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD eyes.violasystem.net 6.1-PRERELEASE FreeBSD 6.1-PRERELEASE #0: Sat Feb 18 00:16:19 JST 2006 kazuaki@eyes.violasystem.net:/usr/obj/usr/src/sys/EYES i386


	
>Description:
	If you run the following command:
	% ls -l /usr/bin | env LANG=ja_JP.eucJP sort -n -k 5
	Probably you get wrong result.
	It is not sorted by fifth column correctly.
	If you run:
	% ls -l /usr/bin | env LANG=C sort -n -k 5
	The result is OK.
>How-To-Repeat:
	
>Fix:

	Blank characters are skipped at the top of numcompare() function.
	But in case of MB_CUR_MAX > 1, more than MB_LEN_MAX characters are not
	skipped.
	MB_LEN_MAX is 6 (defined in /usr/include/limits.h).
	So if you have more than 6 blank characters, you can get wrong result.

	The following patch resolves this problem.

--- sort.c.patch begins here ---
--- contrib/gnu-sort/src/sort.c.orig	Thu Aug 12 14:46:04 2004
+++ contrib/gnu-sort/src/sort.c	Sun Feb 19 23:22:49 2006
@@ -1450,8 +1450,8 @@
   if (MB_CUR_MAX > 1)
     {
       size_t mblength;
-      size_t alen = strnlen (a, MB_LEN_MAX);
-      size_t blen = strnlen (b, MB_LEN_MAX);
+      size_t alen = strlen (a);
+      size_t blen = strlen (b);
 
       while (ismbblank (a, alen, &mblength))
 	a += mblength, alen -= mblength;
--- sort.c.patch ends here ---


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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200602191646.k1JGkfFH009260>