diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-04 02:48:14 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-12-04 02:48:14 +0100 |
commit | 6dc0ace10943b9f8e004b63277dc1186594f0450 (patch) | |
tree | fbfea896312234df57f330e16629c246a660aea0 | |
parent | 6a110c969f357d5ab3503660c6404a1ee9d916eb (diff) | |
download | busybox-w32-6dc0ace10943b9f8e004b63277dc1186594f0450.tar.gz busybox-w32-6dc0ace10943b9f8e004b63277dc1186594f0450.tar.bz2 busybox-w32-6dc0ace10943b9f8e004b63277dc1186594f0450.zip |
grep: fix a case when -o loops forever
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | findutils/grep.c | 8 | ||||
-rwxr-xr-x | testsuite/grep.tests | 5 |
2 files changed, 10 insertions, 3 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 776a629be..9dc2f1942 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
@@ -229,8 +229,8 @@ static int grep_file(FILE *file) | |||
229 | char *line = NULL; | 229 | char *line = NULL; |
230 | ssize_t line_len; | 230 | ssize_t line_len; |
231 | size_t line_alloc_len; | 231 | size_t line_alloc_len; |
232 | #define rm_so start[0] | 232 | # define rm_so start[0] |
233 | #define rm_eo end[0] | 233 | # define rm_eo end[0] |
234 | #endif | 234 | #endif |
235 | #if ENABLE_FEATURE_GREP_CONTEXT | 235 | #if ENABLE_FEATURE_GREP_CONTEXT |
236 | int print_n_lines_after = 0; | 236 | int print_n_lines_after = 0; |
@@ -238,7 +238,7 @@ static int grep_file(FILE *file) | |||
238 | int idx = 0; /* used for iteration through the circular buffer */ | 238 | int idx = 0; /* used for iteration through the circular buffer */ |
239 | #else | 239 | #else |
240 | enum { print_n_lines_after = 0 }; | 240 | enum { print_n_lines_after = 0 }; |
241 | #endif /* ENABLE_FEATURE_GREP_CONTEXT */ | 241 | #endif |
242 | 242 | ||
243 | while ( | 243 | while ( |
244 | #if !ENABLE_EXTRA_COMPAT | 244 | #if !ENABLE_EXTRA_COMPAT |
@@ -377,6 +377,8 @@ static int grep_file(FILE *file) | |||
377 | print_line(line + gl->matched_range.rm_so, | 377 | print_line(line + gl->matched_range.rm_so, |
378 | end - gl->matched_range.rm_so, | 378 | end - gl->matched_range.rm_so, |
379 | linenum, ':'); | 379 | linenum, ':'); |
380 | if (old == '\0') | ||
381 | break; | ||
380 | line[end] = old; | 382 | line[end] = old; |
381 | #if !ENABLE_EXTRA_COMPAT | 383 | #if !ENABLE_EXTRA_COMPAT |
382 | if (regexec(&gl->compiled_regex, line + end, | 384 | if (regexec(&gl->compiled_regex, line + end, |
diff --git a/testsuite/grep.tests b/testsuite/grep.tests index 6e14f91ce..64df19ced 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests | |||
@@ -90,4 +90,9 @@ testing "grep -E -o prints all matches" \ | |||
90 | "00:19:3E:00:AA:5E\n00:1D:60:3D:3A:FB\n00:22:43:49:FB:AA\n" \ | 90 | "00:19:3E:00:AA:5E\n00:1D:60:3D:3A:FB\n00:22:43:49:FB:AA\n" \ |
91 | "" "00:19:3E:00:AA:5E 00:1D:60:3D:3A:FB 00:22:43:49:FB:AA\n" | 91 | "" "00:19:3E:00:AA:5E 00:1D:60:3D:3A:FB 00:22:43:49:FB:AA\n" |
92 | 92 | ||
93 | testing "grep -o does not loop forever" \ | ||
94 | 'grep -o "[^/]*$"' \ | ||
95 | "test\n" \ | ||
96 | "" "/var/test\n" | ||
97 | |||
93 | exit $FAILCOUNT | 98 | exit $FAILCOUNT |