diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-09-19 22:06:40 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-09-19 22:06:40 +0200 |
commit | 8aa7cf305ba5133721aa9852b398cbf1867fc857 (patch) | |
tree | 996b5b68c9b4004ffd65d954f19f5bbbe21bc71b /coreutils/sort.c | |
parent | f085344d5c4de46d0ef3e15a97ef444fd7cc3194 (diff) | |
download | busybox-w32-8aa7cf305ba5133721aa9852b398cbf1867fc857.tar.gz busybox-w32-8aa7cf305ba5133721aa9852b398cbf1867fc857.tar.bz2 busybox-w32-8aa7cf305ba5133721aa9852b398cbf1867fc857.zip |
sort: fix -kN,M handling (was including last separator into the comparison)
Testcase:
$ printf '%s\n' a/a:a a:b | sort -t: -k1,1
a:b
a/a:a
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/sort.c')
-rw-r--r-- | coreutils/sort.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 1cb4c3e3f..36f02543b 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
@@ -25,14 +25,14 @@ | |||
25 | //usage: "\n -f Ignore case" | 25 | //usage: "\n -f Ignore case" |
26 | //usage: "\n -g General numerical sort" | 26 | //usage: "\n -g General numerical sort" |
27 | //usage: "\n -i Ignore unprintable characters" | 27 | //usage: "\n -i Ignore unprintable characters" |
28 | //usage: "\n -k Sort key" | ||
29 | //usage: "\n -M Sort month" | 28 | //usage: "\n -M Sort month" |
30 | //usage: ) | 29 | //usage: ) |
30 | //-h, --human-numeric-sort: compare human readable numbers (e.g., 2K 1G) | ||
31 | //usage: "\n -n Sort numbers" | 31 | //usage: "\n -n Sort numbers" |
32 | //usage: IF_FEATURE_SORT_BIG( | 32 | //usage: IF_FEATURE_SORT_BIG( |
33 | //usage: "\n -o Output to file" | 33 | //usage: "\n -o Output to file" |
34 | //usage: "\n -k Sort by key" | 34 | //usage: "\n -t CHAR Field separator" |
35 | //usage: "\n -t CHAR Key separator" | 35 | //usage: "\n -k N[,M] Sort by Nth field" |
36 | //usage: ) | 36 | //usage: ) |
37 | //usage: "\n -r Reverse sort order" | 37 | //usage: "\n -r Reverse sort order" |
38 | //usage: IF_FEATURE_SORT_BIG( | 38 | //usage: IF_FEATURE_SORT_BIG( |
@@ -143,6 +143,9 @@ static char *get_key(char *str, struct sort_key *key, int flags) | |||
143 | } | 143 | } |
144 | } | 144 | } |
145 | } | 145 | } |
146 | /* Remove last delim: "abc:def:" => "abc:def" */ | ||
147 | if (key_separator && j && end != 0) | ||
148 | end--; | ||
146 | } | 149 | } |
147 | if (!j) start = end; | 150 | if (!j) start = end; |
148 | } | 151 | } |
@@ -163,7 +166,8 @@ static char *get_key(char *str, struct sort_key *key, int flags) | |||
163 | if (start > len) start = len; | 166 | if (start > len) start = len; |
164 | } | 167 | } |
165 | /* Make the copy */ | 168 | /* Make the copy */ |
166 | if (end < start) end = start; | 169 | if (end < start) |
170 | end = start; | ||
167 | str = xstrndup(str+start, end-start); | 171 | str = xstrndup(str+start, end-start); |
168 | /* Handle -d */ | 172 | /* Handle -d */ |
169 | if (flags & FLAG_d) { | 173 | if (flags & FLAG_d) { |