From: Sami Kerola Date: Sun, 17 Jun 2012 12:34:30 +0000 (+0200) Subject: more: fix search repetition regression X-Git-Tag: v2.22-rc1~267^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=02206bfbd7ebdfcab02fd828e0b23f6b42f1cc5b;p=thirdparty%2Futil-linux.git more: fix search repetition regression Commit 596007ef6a37b708f44286932eed667b316e5f70 introduced a bug crashing more always when a text search was repeated with 'n' command. Signed-off-by: Sami Kerola --- diff --git a/text-utils/more.c b/text-utils/more.c index b759859d16..acd58c8b01 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -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; } }