diff options
author | Sami Kerola | 2012-06-17 14:34:30 +0200 |
---|---|---|
committer | Sami Kerola | 2012-06-17 18:00:00 +0200 |
commit | 02206bfbd7ebdfcab02fd828e0b23f6b42f1cc5b (patch) | |
tree | 0fb3dfdded17c8a94ce3a8aabdeaba47f873382f /text-utils | |
parent | lscpu: values in /proc/bus/pci/devices are always unsigned (diff) | |
download | kernel-qcow2-util-linux-02206bfbd7ebdfcab02fd828e0b23f6b42f1cc5b.tar.gz kernel-qcow2-util-linux-02206bfbd7ebdfcab02fd828e0b23f6b42f1cc5b.tar.xz kernel-qcow2-util-linux-02206bfbd7ebdfcab02fd828e0b23f6b42f1cc5b.zip |
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 <kerolasa@iki.fi>
Diffstat (limited to 'text-utils')
-rw-r--r-- | text-utils/more.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/text-utils/more.c b/text-utils/more.c index b759859d1..acd58c8b0 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; } } |