shithub: sam

Download patch

ref: ffc54196129ee5e4d21bbdd7c46ad2385d7e6309
parent: 024683a13d15fa973a482c6ad00d972bdf20669f
author: Aidan K. Wiggins <akw@oneiri.one>
date: Sat Jan 25 15:47:02 EST 2025

Fix hdata bounds.

--- a/samterm/main.c
+++ b/samterm/main.c
@@ -387,18 +387,16 @@
 {
 	Rasp *r;
 	int len;
+	int c;
 
 	r = &t->rasp;
-	if(rcontig(r, n, m, 1) == (m-n))
-		return;
-
 	do{
 		len = m - n;
 		if(len > TBLOCKSIZE)
 			len = TBLOCKSIZE;
-		if(rcontig(r, n, n+len, 1) == len)
+		if((c = rcontig(r, n, n+len, 1)) == len)
 			continue;
-		outTsls(Trequest, t->tag, n, len);
+		outTsls(Trequest, t->tag, n+c, len-c);
 		t->lock++;
 		if(waitforio(1) & (1 << RHost))
 			rcv();
@@ -408,7 +406,7 @@
 long
 bound(Text *t, long a)
 {
-	if(a > t->rasp.nrunes)
+	if(a >= t->rasp.nrunes)
 		a = t->rasp.nrunes-1;
 	if(a < 0)
 		a = 0;
--- a/samterm/mesg.c
+++ b/samterm/mesg.c
@@ -217,8 +217,7 @@
 		r = buf;
 		for(i = offset; i < count; i += w)
 			w = chartorune(r++, (char*)indata+i);
-		count -= offset;
-		l += hdata(m, l, buf, count);
+		l += hdata(m, l, buf, r-buf);
 	Checkscroll:
 		if(m == cmd.tag){
 			for(i = 0; i < NL; i++){
@@ -712,10 +711,10 @@
 		if(a < l->p1)
 			l->p1+=new;
 		/* must prevent b temporarily becoming unsigned */
-		if(!req || a<o || (b>0 && b>l->f.nchars) ||
-		    (l->f.nchars==0 && a-o>0))
+		if(!req || a<o || (b > 0 && b > l->f.nchars) ||
+		    (l->f.nchars == 0 && a-o > 0))
 			continue;
-		if(new>TBLOCKSIZE)
+		if(new > TBLOCKSIZE)
 			new = TBLOCKSIZE;
 		outTsls(Trequest, m, a, (int)new);
 		t->lock++;