aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2015-10-19 19:27:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2015-10-19 19:27:26 +0200
commit0506e292b518a04846ae1f611ecc0633969a2801 (patch)
tree14dfac41239a1a67fdd4d895b0b27d1ba77fd383
parentd1ed3e68b8080161642cc106099c0a17ac7892e6 (diff)
downloadbusybox-w32-0506e292b518a04846ae1f611ecc0633969a2801.tar.gz
busybox-w32-0506e292b518a04846ae1f611ecc0633969a2801.tar.bz2
busybox-w32-0506e292b518a04846ae1f611ecc0633969a2801.zip
sort: fix ENDCHAR handling in "-kSTART,N.ENDCHAR"
function old new delta get_key 505 503 -2 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/sort.c7
-rwxr-xr-xtestsuite/sort.tests8
2 files changed, 12 insertions, 3 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c
index f2bc5335f..07d903388 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -160,17 +160,18 @@ static char *get_key(char *str, struct sort_key *key, int flags)
160 if (!j) start = end; 160 if (!j) start = end;
161 } 161 }
162 /* Strip leading whitespace if necessary */ 162 /* Strip leading whitespace if necessary */
163//XXX: skip_whitespace()
164 if (flags & FLAG_b) 163 if (flags & FLAG_b)
164 /* not using skip_whitespace() for speed */
165 while (isspace(str[start])) start++; 165 while (isspace(str[start])) start++;
166 /* Strip trailing whitespace if necessary */ 166 /* Strip trailing whitespace if necessary */
167 if (flags & FLAG_bb) 167 if (flags & FLAG_bb)
168 while (end > start && isspace(str[end-1])) end--; 168 while (end > start && isspace(str[end-1])) end--;
169 /* Handle offsets on start and end */ 169 /* -kSTART,N.ENDCHAR: honor ENDCHAR (1-based) */
170 if (key->range[3]) { 170 if (key->range[3]) {
171 end += key->range[3] - 1; 171 end = key->range[3];
172 if (end > len) end = len; 172 if (end > len) end = len;
173 } 173 }
174 /* -kN.STARTCHAR[,...]: honor STARTCHAR (1-based) */
174 if (key->range[1]) { 175 if (key->range[1]) {
175 start += key->range[1] - 1; 176 start += key->range[1] - 1;
176 if (start > len) start = len; 177 if (start > len) start = len;
diff --git a/testsuite/sort.tests b/testsuite/sort.tests
index 39c7af738..c51a8e475 100755
--- a/testsuite/sort.tests
+++ b/testsuite/sort.tests
@@ -106,6 +106,14 @@ a/a:a
106a:b 106a:b
107" "" 107" ""
108 108
109testing "sort with ENDCHAR" "sort -t. -k1,1.1 -k2 input" "\
110ab.1
111aa.2
112" "\
113aa.2
114ab.1
115" ""
116
109testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\ 117testing "glibc build sort" "sort -t. -k 1,1 -k 2n,2n -k 3 input" "\
110GLIBC_2.1 118GLIBC_2.1
111GLIBC_2.1.1 119GLIBC_2.1.1