On Tue, Dec 31, 2019 at 02:35:57PM -0800, Michael Forney wrote:
> On 2019-12-31, Richard Ipsum <[email protected]> wrote:
> > When field_start is equal to field_end use field N as the sort key.
> 
> I think this is not just a problem with `-k n,n`, but any time
> field_end is specified. Only up to the beginning of the end field is
> compared (if there are more fields after it).

True

> 
> I think we should keep the invariant that a->data + a->len is the end
> of the line, even though end.len isn't used after the call to
> skipcolumn(&end, 0).
> 
> What do you think about the following diff instead?
> 
> diff --git a/sort.c b/sort.c
> index dfc383f..a51997f 100644
> --- a/sort.c
> +++ b/sort.c
> @@ -66,11 +66,10 @@ skipcolumn(struct line *a, int skip_to_next_col)
> 
>       if (fieldsep) {
>               if ((s = memmem(a->data, a->len, fieldsep, fieldseplen))) {
> -                     if (skip_to_next_col) {
> +                     if (skip_to_next_col)
>                               s += fieldseplen;
> -                             a->len -= s - a->data;
> -                             a->data = s;
> -                     }
> +                     a->len -= s - a->data;
> +                     a->data = s;
>               } else {
>                       a->data += a->len - 1;
>                       a->len = 1;
> 

Looks good

Thanks,
Richard

Reply via email to