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 /findutils | |
parent | 07f417b6ab92e0429f302ff6783bb9681b60120e (diff) | |
download | busybox-3ba2df874ca27f075a0897210d8dce6c56646e60.tar.gz |
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>
Diffstat (limited to 'findutils')
-rw-r--r-- | findutils/grep.c | 8 |
1 files changed, 6 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) } else { #if ENABLE_EXTRA_COMPAT unsigned start_pos; +#else + int match_flg; #endif char *match_at; @@ -392,6 +394,7 @@ static int grep_file(FILE *file) #if !ENABLE_EXTRA_COMPAT gl->matched_range.rm_so = 0; gl->matched_range.rm_eo = 0; + match_flg = 0; #else start_pos = 0; #endif @@ -400,7 +403,7 @@ static int grep_file(FILE *file) //bb_error_msg("'%s' start_pos:%d line_len:%d", match_at, start_pos, line_len); if ( #if !ENABLE_EXTRA_COMPAT - regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, 0) == 0 + regexec(&gl->compiled_regex, match_at, 1, &gl->matched_range, match_flg) == 0 #else re_search(&gl->compiled_regex, match_at, line_len, start_pos, /*range:*/ line_len, @@ -415,7 +418,7 @@ static int grep_file(FILE *file) found = 1; } else { char c = ' '; - if (gl->matched_range.rm_so) + 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]; @@ -432,6 +435,7 @@ static int grep_file(FILE *file) #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; } #else |