diff options
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/sort.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/coreutils/sort.c b/coreutils/sort.c index 36f02543b..c2e8bb8de 100644 --- a/coreutils/sort.c +++ b/coreutils/sort.c | |||
| @@ -106,7 +106,9 @@ static struct sort_key { | |||
| 106 | 106 | ||
| 107 | static char *get_key(char *str, struct sort_key *key, int flags) | 107 | static char *get_key(char *str, struct sort_key *key, int flags) |
| 108 | { | 108 | { |
| 109 | int start = 0, end = 0, len, j; | 109 | int start = start; /* for compiler */ |
| 110 | int end; | ||
| 111 | int len, j; | ||
| 110 | unsigned i; | 112 | unsigned i; |
| 111 | 113 | ||
| 112 | /* Special case whole string, so we don't have to make a copy */ | 114 | /* Special case whole string, so we don't have to make a copy */ |
| @@ -123,12 +125,15 @@ static char *get_key(char *str, struct sort_key *key, int flags) | |||
| 123 | end = len; | 125 | end = len; |
| 124 | /* Loop through fields */ | 126 | /* Loop through fields */ |
| 125 | else { | 127 | else { |
| 128 | unsigned char ch = 0; | ||
| 129 | |||
| 126 | end = 0; | 130 | end = 0; |
| 127 | for (i = 1; i < key->range[2*j] + j; i++) { | 131 | for (i = 1; i < key->range[2*j] + j; i++) { |
| 128 | if (key_separator) { | 132 | if (key_separator) { |
| 129 | /* Skip body of key and separator */ | 133 | /* Skip body of key and separator */ |
| 130 | while (str[end]) { | 134 | while ((ch = str[end]) != '\0') { |
| 131 | if (str[end++] == key_separator) | 135 | end++; |
| 136 | if (ch == key_separator) | ||
| 132 | break; | 137 | break; |
| 133 | } | 138 | } |
| 134 | } else { | 139 | } else { |
| @@ -136,7 +141,7 @@ static char *get_key(char *str, struct sort_key *key, int flags) | |||
| 136 | while (isspace(str[end])) | 141 | while (isspace(str[end])) |
| 137 | end++; | 142 | end++; |
| 138 | /* Skip body of key */ | 143 | /* Skip body of key */ |
| 139 | while (str[end]) { | 144 | while (str[end] != '\0') { |
| 140 | if (isspace(str[end])) | 145 | if (isspace(str[end])) |
| 141 | break; | 146 | break; |
| 142 | end++; | 147 | end++; |
| @@ -144,8 +149,13 @@ static char *get_key(char *str, struct sort_key *key, int flags) | |||
| 144 | } | 149 | } |
| 145 | } | 150 | } |
| 146 | /* Remove last delim: "abc:def:" => "abc:def" */ | 151 | /* Remove last delim: "abc:def:" => "abc:def" */ |
| 147 | if (key_separator && j && end != 0) | 152 | if (j && ch) { |
| 153 | //if (str[end-1] != key_separator) | ||
| 154 | // bb_error_msg(_and_die("BUG! " | ||
| 155 | // "str[start:%d,end:%d]:'%.*s'", | ||
| 156 | // start, end, (int)(end-start), &str[start]); | ||
| 148 | end--; | 157 | end--; |
| 158 | } | ||
| 149 | } | 159 | } |
| 150 | if (!j) start = end; | 160 | if (!j) start = end; |
| 151 | } | 161 | } |
