sort: Consider end field in keydef when additional fields are present

Currently, if the delimiter is found after the last field of a keydef,
only up to the beginning of the field is considered. This breaks `sort
-k N,N`, as well as whenever the sorted order comes down to that last
field.

Thanks to Richard Ipsum for the bug report and proposed patch.
This commit is contained in:
Michael Forney 2020-01-01 12:16:16 -08:00
parent a8dc42e6b5
commit e9bfb97808

3
sort.c
View File

@ -66,11 +66,10 @@ skipcolumn(struct line *a, int skip_to_next_col)
if (fieldsep) { if (fieldsep) {
if ((s = memmem(a->data, a->len, fieldsep, fieldseplen))) { if ((s = memmem(a->data, a->len, fieldsep, fieldseplen))) {
if (skip_to_next_col) { if (skip_to_next_col)
s += fieldseplen; s += fieldseplen;
a->len -= s - a->data; a->len -= s - a->data;
a->data = s; a->data = s;
}
} else { } else {
a->data += a->len - 1; a->data += a->len - 1;
a->len = 1; a->len = 1;