shithub: riscv

Download patch

ref: af0de5ada83205e6016b108a2f19dbc5782d5e8e
parent: d8999511e0921e2aaa45f862c5b4ca9098d78a96
author: aiju <devnull@localhost>
date: Wed Feb 7 13:53:08 EST 2018

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

--- a/sys/src/cmd/sort.c
+++ b/sys/src/cmd/sort.c
@@ -941,7 +941,7 @@
 uchar*
 skip(uchar *l, int n1, int n2, int bflag, int endfield)
 {
-	int i, c, tc;
+	int i, c, ln, tc;
 	Rune r;
 
 	if(endfield && n1 < 0)
@@ -948,6 +948,7 @@
 		return 0;
 
 	c = *l++;
+	ln = 1;
 	tc = args.tabchar;
 	if(tc) {
 		if(tc < Runeself) {
@@ -962,15 +963,15 @@
 			}
 		} else {
 			l--;
-			l += chartorune(&r, (char*)l);
+			l += ln = chartorune(&r, (char*)l);
 			for(i=n1; i>0; i--) {
 				while(r != tc) {
 					if(r == '\n')
 						return 0;
-					l += chartorune(&r, (char*)l);
+					l += ln = chartorune(&r, (char*)l);
 				}
 				if(!(endfield && i == 1))
-					l += chartorune(&r, (char*)l);
+					l += ln = chartorune(&r, (char*)l);
 			}
 			c = r;
 		}
@@ -987,10 +988,12 @@
 	}
 
 	if(bflag)
-		while(c == ' ' || c == '\t')
+		while(c == ' ' || c == '\t'){
 			c = *l++;
+			ln = 1;
+		}
 
-	l--;
+	l -= ln;
 	for(i=n2; i>0; i--) {
 		c = *l;
 		if(c < Runeself) {