fix sort(1) bug where it incorrectly included the field separator in the comparison if it was >= Runeself

This commit is contained in:
aiju 2018-02-07 18:53:08 +00:00
parent d8999511e0
commit af0de5ada8

View file

@ -941,13 +941,14 @@ doargs(int argc, char *argv[])
uchar* uchar*
skip(uchar *l, int n1, int n2, int bflag, int endfield) skip(uchar *l, int n1, int n2, int bflag, int endfield)
{ {
int i, c, tc; int i, c, ln, tc;
Rune r; Rune r;
if(endfield && n1 < 0) if(endfield && n1 < 0)
return 0; return 0;
c = *l++; c = *l++;
ln = 1;
tc = args.tabchar; tc = args.tabchar;
if(tc) { if(tc) {
if(tc < Runeself) { if(tc < Runeself) {
@ -962,15 +963,15 @@ skip(uchar *l, int n1, int n2, int bflag, int endfield)
} }
} else { } else {
l--; l--;
l += chartorune(&r, (char*)l); l += ln = chartorune(&r, (char*)l);
for(i=n1; i>0; i--) { for(i=n1; i>0; i--) {
while(r != tc) { while(r != tc) {
if(r == '\n') if(r == '\n')
return 0; return 0;
l += chartorune(&r, (char*)l); l += ln = chartorune(&r, (char*)l);
} }
if(!(endfield && i == 1)) if(!(endfield && i == 1))
l += chartorune(&r, (char*)l); l += ln = chartorune(&r, (char*)l);
} }
c = r; c = r;
} }
@ -987,10 +988,12 @@ skip(uchar *l, int n1, int n2, int bflag, int endfield)
} }
if(bflag) if(bflag)
while(c == ' ' || c == '\t') while(c == ' ' || c == '\t'){
c = *l++; c = *l++;
ln = 1;
}
l--; l -= ln;
for(i=n2; i>0; i--) { for(i=n2; i>0; i--) {
c = *l; c = *l;
if(c < Runeself) { if(c < Runeself) {