diff options
| author | Bartosz Golaszewski <bartekgola@gmail.com> | 2014-02-07 17:14:37 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2014-02-07 17:15:56 +0100 |
| commit | 3ba2df874ca27f075a0897210d8dce6c56646e60 (patch) | |
| tree | 8d8b56ec8092ab4da85abd275998b2da457dbef7 | |
| parent | 07f417b6ab92e0429f302ff6783bb9681b60120e (diff) | |
| download | busybox-w32-3ba2df874ca27f075a0897210d8dce6c56646e60.tar.gz busybox-w32-3ba2df874ca27f075a0897210d8dce6c56646e60.tar.bz2 busybox-w32-3ba2df874ca27f075a0897210d8dce6c56646e60.zip | |
grep: properly handle grep -w "^str" in !EXTRA_COMPAT case too
function old new delta
grep_file 1267 1288 +21
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
| -rw-r--r-- | findutils/grep.c | 8 | ||||
| -rwxr-xr-x | testsuite/grep.tests | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/findutils/grep.c b/findutils/grep.c index a7bc4ca9e..76859464f 100644 --- a/findutils/grep.c +++ b/findutils/grep.c | |||
| @@ -375,6 +375,8 @@ static int grep_file(FILE *file) | |||
| 375 | } else { | 375 | } else { |
| 376 | #if ENABLE_EXTRA_COMPAT | 376 | #if ENABLE_EXTRA_COMPAT |
| 377 | unsigned start_pos; | 377 | unsigned start_pos; |
| 378 | #else | ||
| 379 | int match_flg; | ||
| 378 | #endif | 380 | #endif |
| 379 | char *match_at; | 381 | char *match_at; |
| 380 | 382 | ||
| @@ -392,6 +394,7 @@ static int grep_file(FILE *file) | |||
| 392 | #if !ENABLE_EXTRA_COMPAT | 394 | #if !ENABLE_EXTRA_COMPAT |
| 393 | gl->matched_range.rm_so = 0; | 395 | gl->matched_range.rm_so = 0; |
| 394 | gl->matched_range.rm_eo = 0; | 396 | gl->matched_range.rm_eo = 0; |
| 397 | match_flg = 0; | ||
| 395 | #else | 398 | #else |
| 396 | start_pos = 0; | 399 | start_pos = 0; |
| 397 | #endif | 400 | #endif |
| @@ -400,7 +403,7 @@ static int grep_file(FILE *file) | |||
| 400 | //bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len); | 403 | //bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len); |
| 401 | if ( | 404 | if ( |
| 402 | #if !ENABLE_EXTRA_COMPAT | 405 | #if !ENABLE_EXTRA_COMPAT |
| 403 | regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0 | 406 | regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0 |
| 404 | #else | 407 | #else |
| 405 | re_search(&gl->compiled_regex, match_at, line_len, | 408 | re_search(&gl->compiled_regex, match_at, line_len, |
| 406 | start_pos, /*range:*/ line_len, | 409 | start_pos, /*range:*/ line_len, |
| @@ -415,7 +418,7 @@ static int grep_file(FILE *file) | |||
| 415 | found = 1; | 418 | found = 1; |
| 416 | } else { | 419 | } else { |
| 417 | char c = ' '; | 420 | char c = ' '; |
| 418 | if (gl->matched_range.rm_so) | 421 | if (match_at > line || gl->matched_range.rm_so != 0) |
| 419 | c = match_at[gl->matched_range.rm_so - 1]; | 422 | c = match_at[gl->matched_range.rm_so - 1]; |
| 420 | if (!isalnum(c) && c != '_') { | 423 | if (!isalnum(c) && c != '_') { |
| 421 | c = match_at[gl->matched_range.rm_eo]; | 424 | c = match_at[gl->matched_range.rm_eo]; |
| @@ -432,6 +435,7 @@ static int grep_file(FILE *file) | |||
| 432 | #if !ENABLE_EXTRA_COMPAT | 435 | #if !ENABLE_EXTRA_COMPAT |
| 433 | if (gl->matched_range.rm_eo != 0) { | 436 | if (gl->matched_range.rm_eo != 0) { |
| 434 | match_at += gl->matched_range.rm_eo; | 437 | match_at += gl->matched_range.rm_eo; |
| 438 | match_flg |= REG_NOTBOL; | ||
| 435 | goto opt_w_again; | 439 | goto opt_w_again; |
| 436 | } | 440 | } |
| 437 | #else | 441 | #else |
diff --git a/testsuite/grep.tests b/testsuite/grep.tests index 412efffbb..74b0eb63f 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests | |||
| @@ -159,6 +159,12 @@ testing "grep -w ^ doesn't hang" \ | |||
| 159 | "anything\n" \ | 159 | "anything\n" \ |
| 160 | "" | 160 | "" |
| 161 | 161 | ||
| 162 | testing "grep -w word doesn't match wordword" \ | ||
| 163 | "grep -w word input" \ | ||
| 164 | "" \ | ||
| 165 | "wordword\n" \ | ||
| 166 | "" | ||
| 167 | |||
| 162 | # testing "test name" "commands" "expected result" "file input" "stdin" | 168 | # testing "test name" "commands" "expected result" "file input" "stdin" |
| 163 | # file input will be file called "input" | 169 | # file input will be file called "input" |
| 164 | # test can create a file "actual" instead of writing to stdout | 170 | # test can create a file "actual" instead of writing to stdout |
