summaryrefslogtreecommitdiff
path: root/findutils/grep.c
diff options
context:
space:
mode:
authorDenys Vlasenko2010-08-23 02:53:58 +0200
committerDenys Vlasenko2010-08-23 02:53:58 +0200
commitdc04439450e5929880205d920de3a26409727563 (patch)
tree5ee9110f0cb3ddd01f2ca6a5d7da87ee4a910443 /findutils/grep.c
parent941fce89fa346e06e936d4d3b58773c836127fd7 (diff)
downloadbusybox-dc04439450e5929880205d920de3a26409727563.zip
busybox-dc04439450e5929880205d920de3a26409727563.tar.gz
Version 1.17.2: apply post 1.17.1 fixes, replace patch applet by Rob's version
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils/grep.c')
-rw-r--r--findutils/grep.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index ac290a9..183d026 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -461,15 +461,19 @@ static int grep_file(FILE *file)
if (found)
print_line(gl->pattern, strlen(gl->pattern), linenum, ':');
} else while (1) {
+ unsigned start = gl->matched_range.rm_so;
unsigned end = gl->matched_range.rm_eo;
+ unsigned len = end - start;
char old = line[end];
line[end] = '\0';
- print_line(line + gl->matched_range.rm_so,
- end - gl->matched_range.rm_so,
- linenum, ':');
+ /* Empty match is not printed: try "echo test | grep -o ''" */
+ if (len != 0)
+ print_line(line + start, len, linenum, ':');
if (old == '\0')
break;
line[end] = old;
+ if (len == 0)
+ end++;
#if !ENABLE_EXTRA_COMPAT
if (regexec(&gl->compiled_regex, line + end,
1, &gl->matched_range, REG_NOTBOL) != 0)