diff options
author | wxj <wangxiaojianffgz@163.com> | 2016-12-25 15:58:10 +0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-12-25 21:18:19 -0600 |
commit | 7a7378629cc3d67b27c64452391b80aa8a5a6481 (patch) | |
tree | 52e9ab10ae6357a24a9c970005809e410fc13151 /toys | |
parent | 4582497e8839d7a3d73aa71f76c2aae915202d41 (diff) | |
download | toybox-7a7378629cc3d67b27c64452391b80aa8a5a6481.tar.gz |
Fix a bug for sort. When the key_separator is not space, the sort commandline tool fails to sort by the 3rd,4th,etc column. For example: when you exec
$ sort -t',' -k 3n
on a file which cotains:
1,2,3,4
2,3,4,1
4,1,2,3
3,4,1,2
you got:
4,1,2,3
1,2,3,4
2,3,4,1
3,4,1,2
but the expected output should be:
3,4,1,2
4,1,2,3
1,2,3,4
2,3,4,1
The bug is due to the dependency of "isspace(str[end])" at line 113.
When searching for the non-space key_separator, the search stopped just at the position of first key_separator it met.
The bug can be easily fixed by adding "end++" when the search have found one separator and exit the for loop.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/posix/sort.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/toys/posix/sort.c b/toys/posix/sort.c index a1722fb2..2b0f5c08 100644 --- a/toys/posix/sort.c +++ b/toys/posix/sort.c @@ -115,7 +115,10 @@ static char *get_key_data(char *str, struct sort_key *key, int flags) // Skip body of key for (; str[end]; end++) { if (TT.key_separator) { - if (str[end]==*TT.key_separator) break; + if (str[end]==*TT.key_separator) { + end++; + break; + } } else if (isspace(str[end])) break; } } |