shithub: riscv

Download patch

ref: 50493215dd272df2ec35190d47640160dd61bc0e
parent: aa369a07a9cec2db35ad928e2ad1f3aaeb993e45
author: cinap_lenrek <[email protected]>
date: Wed Nov 2 21:46:04 EDT 2011

mothra: fix integer overflow on textview scroll

--- a/sys/src/cmd/mothra/libpanel/textview.c
+++ b/sys/src/cmd/mothra/libpanel/textview.c
@@ -153,6 +153,7 @@
 	Textview *tp;
 	Rectangle r;
 	if(dir!=VERT) return;
+
 	tp=p->data;
 	ul=p->r.min;
 	size=subpt(p->r.max, p->r.min);
@@ -162,14 +163,14 @@
 		SET(yoffs);
 		break;
 	case 1:		/* left -- top moves to pointer */
-		yoffs=tp->yoffs-num*size.y/den;
+		yoffs=(vlong)tp->yoffs-num*size.y/den;
 		if(yoffs<0) yoffs=0;
 		break;
 	case 2:		/* middle -- absolute index of file */
-		yoffs=tp->thgt*num/den;
+		yoffs=(vlong)tp->thgt*num/den;
 		break;
 	case 4:		/* right -- line pointed at moves to top */
-		yoffs=tp->yoffs+num*size.y/den;
+		yoffs=tp->yoffs+(vlong)num*size.y/den;
 		if(yoffs>tp->thgt) yoffs=tp->thgt;
 		break;
 	}
@@ -177,7 +178,7 @@
 		pl_hiliteword(p, tp->hitword, 0);
 		r=pl_outline(p->b, p->r, p->state);
 		pl_rtredraw(p->b, r, tp->text, yoffs, tp->yoffs);
-		tp->yoffs=yoffs;
+		p->scr.pos.y=tp->yoffs=yoffs;
 		pl_fixtextview(p, tp, r);
 	}
 }
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -171,7 +171,6 @@
 	if(s.pos.y > s.size.y)
 		s.pos.y = s.size.y;
 	plsetscroll(text, s);
-	pldraw(root, screen);
 }
 
 void mkpanels(void){