]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
more: fix search repetition regression
authorSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 12:34:30 +0000 (14:34 +0200)
committerSami Kerola <kerolasa@iki.fi>
Sun, 17 Jun 2012 16:00:00 +0000 (18:00 +0200)
Commit 596007ef6a37b708f44286932eed667b316e5f70 introduced a bug
crashing more always when a text search was repeated with 'n' command.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
text-utils/more.c

index b759859d169ad9c028a80a520d170b0acae75a46..acd58c8b01a01cd50b78182b6266d0f9f2cc7653 100644 (file)
@@ -177,6 +177,7 @@ int         soglitch;               /* terminal has standout mode glitch */
 int            ulglitch;               /* terminal has underline mode glitch */
 int            pstate = 0;             /* current UL state */
 static int     magic(FILE *, char *);
+char           *previousre;            /* previous search() buf[] item */
 struct {
     long chrctr, line;
 } context, screen_start;
@@ -420,6 +421,7 @@ int main(int argc, char **argv) {
            }
            if (srchopt)
            {
+               previousre = xstrdup(initbuf);
                search (initbuf, stdin, 1);
                if (noscroll)
                    left--;
@@ -441,6 +443,7 @@ int main(int argc, char **argv) {
            if (firstf) {
                firstf = 0;
                if (srchopt) {
+                   previousre = xstrdup(initbuf);
                    search (initbuf, f, 1);
                    if (noscroll)
                        left--;
@@ -492,6 +495,7 @@ int main(int argc, char **argv) {
        fnum++;
        firstf = 0;
     }
+    free (previousre);
     reset_tty ();
     exit(EXIT_SUCCESS);
 }
@@ -1332,6 +1336,10 @@ int command (char *filename, register FILE *f)
            fflush (stdout);
            break;
        case 'n':
+           if (!previousre) {
+               more_error (_("No previous regular expression"));
+               break;
+            }
            lastp++;
            /* fallthrough */
        case '/':
@@ -1342,11 +1350,13 @@ int command (char *filename, register FILE *f)
            fflush (stdout);
            if (lastp) {
                putcerr('\r');
-               search (NULL, f, nlines);       /* Use previous r.e. */
+               search (previousre, f, nlines);
            }
            else {
                ttyin (cmdbuf, sizeof(cmdbuf)-2, '/');
                putcerr('\r');
+               free (previousre);
+               previousre = xstrdup(cmdbuf);
                search (cmdbuf, f, nlines);
            }
            ret (dlines-1);
@@ -1647,6 +1657,8 @@ void search(char buf[], FILE *file, register int n)
            end_it (0);
        }
        more_error (_("Pattern not found"));
+       free (previousre);
+       previousre = NULL;
     }
 }