On Tue, Sep 04, 2012 at 09:32:21AM +0000, Mark Lumsden wrote:
> If you don't mind, could you send the diff to tech@?
>
> If there are no objections, I'll commit the diff at the weekend.
>
> mark

The while loop in backsrch in search.c decrements nline even if the
pattern ends up not matching.

1) jot -w '%03d' 100 1 100 > foo.txt
2) mg foo.txt
3) C-x g 23
4) C-r 010 ( or C-r 0^J01 )

After a tweak by lum@ of my original patch and a small tweak by me:

Index: search.c
===================================================================
RCS file: /opt/OpenBSD-CVS/src/usr.bin/mg/search.c,v
retrieving revision 1.40
diff -u -p -r1.40 search.c
--- search.c    25 May 2012 05:16:59 -0000      1.40
+++ search.c    4 Sep 2012 08:36:15 -0000
@@ -737,7 +737,7 @@ backsrch(void)
        struct line     *clp, *tlp;
        int      cbo, tbo, c, i, xcase = 0;
        char    *epp, *pp;
-       int      nline;
+       int      nline, tline;
 
        for (epp = &pat[0]; epp[1] != 0; ++epp);
        clp = curwp->w_dotp;
@@ -762,6 +762,7 @@ backsrch(void)
                        tlp = clp;
                        tbo = cbo;
                        pp = epp;
+                       tline = nline;
                        while (pp != &pat[0]) {
                                if (tbo == 0) {
                                        tlp = lback(tlp);
@@ -774,8 +775,10 @@ backsrch(void)
                                        c = CCHR('J');
                                else
                                        c = lgetc(tlp, tbo);
-                               if (eq(c, *--pp, xcase) == FALSE)
+                               if (eq(c, *--pp, xcase) == FALSE) {
+                                       nline = tline;
                                        goto fail;
+                               }
                        }
                        curwp->w_dotp = tlp;
                        curwp->w_doto = tbo;

-- 
I'm not entirely sure you are real.

Reply via email to