gnu/93566: [patch] sort(1): numeric sort is broken on multi-byte
locales
Kazuaki Oda
ybbkaz at yahoo.co.jp
Sun Feb 19 08:50:04 PST 2006
>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 at 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:
More information about the freebsd-bugs
mailing list