diff options
author | Denys Vlasenko | 2014-02-27 14:56:12 +0100 |
---|---|---|
committer | Denys Vlasenko | 2014-02-27 14:56:12 +0100 |
commit | 83e49ade5724f5b3744660e45179461fe2a1b0f8 (patch) | |
tree | 1f819a54cf2eb2955bea016c4906f70b99c1c20a /findutils | |
parent | 6f068904dc142657bb596f91196f9113f1838cbe (diff) | |
download | busybox-83e49ade5724f5b3744660e45179461fe2a1b0f8.zip busybox-83e49ade5724f5b3744660e45179461fe2a1b0f8.tar.gz |
grep: fix -w match if first match isn't a word, but second is. Closes 4520
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/grep.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index 7685946..f1b6dc6 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -418,13 +418,15 @@ static int grep_file(FILE *file) found = 1; } else { char c = ' '; - if (match_at > line || gl->matched_range.rm_so != 0) + if (match_at > line || gl->matched_range.rm_so != 0) { c = match_at[gl->matched_range.rm_so - 1]; + } if (!isalnum(c) && c != '_') { c = match_at[gl->matched_range.rm_eo]; - if (!c || (!isalnum(c) && c != '_')) { - found = 1; - } else { + } + if (!isalnum(c) && c != '_') { + found = 1; + } else { /* * Why check gl->matched_range.rm_eo? * Zero-length match makes -w skip the line: @@ -433,18 +435,17 @@ static int grep_file(FILE *file) * Without such check, we can loop forever. */ #if !ENABLE_EXTRA_COMPAT - if (gl->matched_range.rm_eo != 0) { - match_at += gl->matched_range.rm_eo; - match_flg |= REG_NOTBOL; - goto opt_w_again; - } + if (gl->matched_range.rm_eo != 0) { + match_at += gl->matched_range.rm_eo; + match_flg |= REG_NOTBOL; + goto opt_w_again; + } #else - if (gl->matched_range.rm_eo > start_pos) { - start_pos = gl->matched_range.rm_eo; - goto opt_w_again; - } -#endif + if (gl->matched_range.rm_eo > start_pos) { + start_pos = gl->matched_range.rm_eo; + goto opt_w_again; } +#endif } } } |