[coreutils] fix the sorting in multibyte locales (NUL-terminate sort keys) - patch by Andreas Schwab (#1146185)

Ondrej Vasik ovasik at fedoraproject.org
Wed Oct 1 12:49:44 UTC 2014


commit cae27396ecf2fee0912a9cf7f828ed4ef22ae6f0
Author: Ondřej Vašík <ovasik at redhat.com>
Date:   Wed Oct 1 14:49:30 2014 +0200

    fix the sorting in multibyte locales (NUL-terminate sort keys) - patch by Andreas Schwab (#1146185)

 coreutils-i18n.patch |   38 ++++++++++++++++++++++++++++++++++----
 coreutils.spec       |    6 +++++-
 2 files changed, 39 insertions(+), 5 deletions(-)
---
diff --git a/coreutils-i18n.patch b/coreutils-i18n.patch
index 633825e..e7005cf 100644
--- a/coreutils-i18n.patch
+++ b/coreutils-i18n.patch
@@ -3132,7 +3132,7 @@ diff -urNp coreutils-8.23-orig/src/sort.c coreutils-8.23/src/sort.c
            else if (key->random)
              diff = compare_random (ta, tlena, tb, tlenb);
            else if (key->version)
-@@ -2695,6 +3135,191 @@ keycompare (struct line const *a, struct
+@@ -2695,6 +3135,209 @@ keycompare (struct line const *a, struct
    return key->reverse ? -diff : diff;
  }
  
@@ -3237,6 +3237,9 @@ diff -urNp coreutils-8.23-orig/src/sort.c coreutils-8.23/src/sort.c
 +      size_t lena = lima <= texta ? 0 : lima - texta;
 +      size_t lenb = limb <= textb ? 0 : limb - textb;
 +
++      char enda IF_LINT (= 0);
++      char endb IF_LINT (= 0);
++
 +      char const *translate = key->translate;
 +      bool const *ignore = key->ignore;
 +
@@ -3254,6 +3257,12 @@ diff -urNp coreutils-8.23-orig/src/sort.c coreutils-8.23/src/sort.c
 +          texta = copy_a; textb = copy_b;
 +          lena = new_len_a; lenb = new_len_b;
 +        }
++      else
++        {
++          /* Use the keys in-place, temporarily null-terminated.  */
++          enda = texta[lena]; texta[lena] = '\0';
++          endb = textb[lenb]; textb[lenb] = '\0';
++        }
 +
 +      if (key->random)
 +        diff = compare_random (texta, lena, textb, lenb);
@@ -3277,13 +3286,22 @@ diff -urNp coreutils-8.23-orig/src/sort.c coreutils-8.23/src/sort.c
 +        diff = 1;
 +      else if (hard_LC_COLLATE && !folding)
 +        {
-+          diff = xmemcoll0 (texta, lena, textb, lenb);
++          diff = xmemcoll0 (texta, lena + 1, textb, lenb + 1);
 +        }
 +      else
-+        diff = memcmp (texta, textb, MIN (lena + 1,lenb + 1));
++        {
++          diff = memcmp (texta, textb, MIN (lena, lenb));
++          if (diff == 0)
++            diff = lena < lenb ? -1 : lena != lenb;
++        }
 +
 +      if (ignore || translate)
 +        free (texta);
++      else
++        {
++          texta[lena] = enda;
++          textb[lenb] = endb;
++        }
 +
 +      if (diff)
 +        goto not_equal;
@@ -4440,7 +4458,18 @@ diff -urNp coreutils-8.23-orig/tests/misc/sort.pl coreutils-8.23/tests/misc/sort
  # Since each test is run with a file name and with redirected stdin,
  # the name in the diagnostic is either the file name or "-".
  # Normalize each diagnostic to use '-'.
-@@ -415,6 +420,37 @@ foreach my $t (@Tests)
+@@ -317,6 +322,10 @@ my @Tests =
+ ["22a", '-k 2,2fd -k 1,1r', {IN=>"3 b\n4 B\n"}, {OUT=>"4 B\n3 b\n"}],
+ ["22b", '-k 2,2d  -k 1,1r', {IN=>"3 b\n4 b\n"}, {OUT=>"4 b\n3 b\n"}],
+ 
++# This fails in Fedora 20, per Göran Uddeborg in: http://bugs.gnu.org/18540
++["23", '-s -k1,1 -t/', {IN=>"a b/x\na-b-c/x\n"}, {OUT=>"a b/x\na-b-c/x\n"},
++ {ENV => "LC_ALL=$mb_locale"}],
++
+ ["no-file1", 'no-file', {EXIT=>2}, {ERR=>$no_file}],
+ # This test failed until 1.22f.  Sort didn't give an error.
+ # From Will Edgington.
+@@ -415,6 +420,38 @@ foreach my $t (@Tests)
        }
    }
  
@@ -4470,6 +4499,7 @@ diff -urNp coreutils-8.23-orig/tests/misc/sort.pl coreutils-8.23/tests/misc/sort
 +        #disable several failing tests until investigation, disable all tests with envvars set
 +        next if (grep {ref $_ eq 'HASH' && exists $_->{ENV}} (@new_t));
 +        next if ($test_name =~ "18g" or $test_name =~ "sort-numeric" or $test_name =~ "08[ab]" or $test_name =~ "03[def]" or $test_name =~ "h4" or $test_name =~ "n1" or $test_name =~ "2[01]a");
++        next if ($test_name =~ "11[ab]"); # avoid FP: expected result differs to MB result due to collation rules.
 +        push @new, ["$test_name-mb", @new_t, {ENV => "LC_ALL=$mb_locale"}];
 +       }
 +    push @Tests, @new;
diff --git a/coreutils.spec b/coreutils.spec
index 97967f7..8b5ad5b 100644
--- a/coreutils.spec
+++ b/coreutils.spec
@@ -1,7 +1,7 @@
 Summary: A set of basic GNU tools commonly used in shell scripts
 Name:    coreutils
 Version: 8.23
-Release: 3%{?dist}
+Release: 4%{?dist}
 License: GPLv3+
 Group:   System Environment/Base
 Url:     http://www.gnu.org/software/coreutils/
@@ -372,6 +372,10 @@ fi
 %{_sbindir}/chroot
 
 %changelog
+* Wed Oct 01 2014 Ondrej Vasik <ovasik at redhat.com> - 8.23-4
+- fix the sorting in multibyte locales (NUL-terminate sort keys)
+  - patch by Andreas Schwab (#1146185)
+
 * Sat Aug 16 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 8.23-3
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild
 


More information about the scm-commits mailing list