Skip to content

Commit

Permalink
acme: fix bufread crash due to typing-point scrolling
Browse files Browse the repository at this point in the history
Acme tracks the most recent typing insertion point and
the home and end keys stop there on their way
up to the top or down to the bottom of the file.
That point should be iq1, and it should be adjusted
properly so that it's always between 0 and t->file->b.nc inclusive.
(This is all code from an external contributor, years old at this
point but new since Plan 9.)

Somehow, sometimes iq1 ends up a little beyond b.nc,
and when passed to textbacknl it crashes acme in bufread.
I can't see how that can happen but if it does, avoid the crash.

It's tempting to pull the insertion point code out entirely
but this is a little less invasive and should fix things for now.

TBR=rsc
https://codereview.appspot.com/107730043
  • Loading branch information
rsc committed Jun 3, 2014
1 parent 8ce5190 commit d466da3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cmd/acme/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,10 @@ texttype(Text *t, Rune r)
case Kend:
typecommit(t);
if(t->iq1 > t->org+t->fr.nchars) {
if(t->iq1 > t->file->b.nc) {
// should not happen, but does. and it will crash textbacknl.
t->iq1 = t->file->b.nc;
}
q0 = textbacknl(t, t->iq1, 1);
textsetorigin(t, q0, TRUE);
} else
Expand Down

0 comments on commit d466da3

Please sign in to comment.