There is a corner case when the screen buffer is only 1 line long
where the loop that looks for the current dot line goes through the
whole buffer until it finds the correct line. This means the line
number decrement is way over what it should be. This diff accounts
for that corner case. ok?

-lum 

Index: basic.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/basic.c,v
retrieving revision 1.34
diff -u -p -r1.34 basic.c
--- basic.c     1 Jun 2012 11:22:06 -0000       1.34
+++ basic.c     5 Jun 2012 21:01:38 -0000
@@ -305,11 +305,12 @@ int
 backpage(int f, int n)
 {
        struct line  *lp, *lp2;
+       int i = 0;
 
        if (!(f & FFARG)) {
                n = curwp->w_ntrows - 2;        /* Default scroll.       */
                if (n <= 0)                     /* Don't blow up if the  */
-                       n = 1;                  /* window is tiny.       */
+                       i = n = 1;              /* window is tiny.       */
        } else if (n < 0)
                return (forwpage(f | FFRAND, -n));
 
@@ -332,10 +333,15 @@ backpage(int f, int n)
 
         lp2 = lforw(lp2);
 
-       /* Move the dot the slow way, for line nos */
-       while (curwp->w_dotp != lp2) {
-               curwp->w_dotp = lback(curwp->w_dotp);
-               curwp->w_dotline--;
+       if (i == 1) {
+                curwp->w_dotp = lback(curwp->w_dotp);
+                curwp->w_dotline--;
+       } else {
+               /* Move the dot the slow way, for line nos */
+               while (curwp->w_dotp != lp2) {
+                       curwp->w_dotp = lback(curwp->w_dotp);
+                       curwp->w_dotline--;
+               }
        }
        curwp->w_doto = 0;
        return (TRUE);

Reply via email to