aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2014-02-27 14:56:12 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2014-02-27 14:56:12 +0100
commit83e49ade5724f5b3744660e45179461fe2a1b0f8 (patch)
tree1f819a54cf2eb2955bea016c4906f70b99c1c20a
parent6f068904dc142657bb596f91196f9113f1838cbe (diff)
downloadbusybox-w32-83e49ade5724f5b3744660e45179461fe2a1b0f8.tar.gz
busybox-w32-83e49ade5724f5b3744660e45179461fe2a1b0f8.tar.bz2
busybox-w32-83e49ade5724f5b3744660e45179461fe2a1b0f8.zip
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>
-rw-r--r--findutils/grep.c29
-rwxr-xr-xtestsuite/grep.tests6
2 files changed, 21 insertions, 14 deletions
diff --git a/findutils/grep.c b/findutils/grep.c
index 76859464f..f1b6dc694 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -418,13 +418,15 @@ static int grep_file(FILE *file)
418 found = 1; 418 found = 1;
419 } else { 419 } else {
420 char c = ' '; 420 char c = ' ';
421 if (match_at > line || gl->matched_range.rm_so != 0) 421 if (match_at > line || gl->matched_range.rm_so != 0) {
422 c = match_at[gl->matched_range.rm_so - 1]; 422 c = match_at[gl->matched_range.rm_so - 1];
423 }
423 if (!isalnum(c) && c != '_') { 424 if (!isalnum(c) && c != '_') {
424 c = match_at[gl->matched_range.rm_eo]; 425 c = match_at[gl->matched_range.rm_eo];
425 if (!c || (!isalnum(c) && c != '_')) { 426 }
426 found = 1; 427 if (!isalnum(c) && c != '_') {
427 } else { 428 found = 1;
429 } else {
428 /* 430 /*
429 * Why check gl->matched_range.rm_eo? 431 * Why check gl->matched_range.rm_eo?
430 * Zero-length match makes -w skip the line: 432 * Zero-length match makes -w skip the line:
@@ -433,18 +435,17 @@ static int grep_file(FILE *file)
433 * Without such check, we can loop forever. 435 * Without such check, we can loop forever.
434 */ 436 */
435#if !ENABLE_EXTRA_COMPAT 437#if !ENABLE_EXTRA_COMPAT
436 if (gl->matched_range.rm_eo != 0) { 438 if (gl->matched_range.rm_eo != 0) {
437 match_at += gl->matched_range.rm_eo; 439 match_at += gl->matched_range.rm_eo;
438 match_flg |= REG_NOTBOL; 440 match_flg |= REG_NOTBOL;
439 goto opt_w_again; 441 goto opt_w_again;
440 } 442 }
441#else 443#else
442 if (gl->matched_range.rm_eo > start_pos) { 444 if (gl->matched_range.rm_eo > start_pos) {
443 start_pos = gl->matched_range.rm_eo; 445 start_pos = gl->matched_range.rm_eo;
444 goto opt_w_again; 446 goto opt_w_again;
445 }
446#endif
447 } 447 }
448#endif
448 } 449 }
449 } 450 }
450 } 451 }
diff --git a/testsuite/grep.tests b/testsuite/grep.tests
index 74b0eb63f..323b3849d 100755
--- a/testsuite/grep.tests
+++ b/testsuite/grep.tests
@@ -165,6 +165,12 @@ testing "grep -w word doesn't match wordword" \
165 "wordword\n" \ 165 "wordword\n" \
166 "" 166 ""
167 167
168testing "grep -w word match second word" \
169 "grep -w word input" \
170 "bword,word\n""wordb,word\n""bwordb,word\n" \
171 "bword,word\n""wordb,word\n""bwordb,word\n" \
172 ""
173
168# testing "test name" "commands" "expected result" "file input" "stdin" 174# testing "test name" "commands" "expected result" "file input" "stdin"
169# file input will be file called "input" 175# file input will be file called "input"
170# test can create a file "actual" instead of writing to stdout 176# test can create a file "actual" instead of writing to stdout