2003-08-15 Elliott Hughes <enh@acm.org> * src/search.c: (EGexecute) fix missing free of multibyte properties, correct returned offset and match_length when -w is in effect. * src/grep.c: fix compiler warning. Index: src/grep.c =================================================================== RCS file: /cvsroot/grep/grep/src/grep.c,v retrieving revision 1.81 diff -u -r1.81 grep.c --- src/grep.c 18 Jan 2003 16:02:30 -0000 1.81 +++ src/grep.c 15 Aug 2003 09:14:41 -0000 @@ -556,7 +556,7 @@ if(color_option) fputs("\33[00m", stdout); fputs("\n", stdout); - ibeg = b + match_size; + ibeg = (char*) (b + match_size); } free (buf); lastout = lim; Index: src/search.c =================================================================== RCS file: /cvsroot/grep/grep/src/search.c,v retrieving revision 1.26 diff -u -r1.26 search.c --- src/search.c 12 Jun 2003 19:58:37 -0000 1.26 +++ src/search.c 15 Aug 2003 09:14:41 -0000 @@ -375,13 +375,7 @@ /* Find a possible match using the KWset matcher. */ size_t offset = kwsexec (kwset, beg, buflim - beg, &kwsm); if (offset == (size_t) -1) - { -#ifdef MBS_SUPPORT - if (MB_CUR_MAX > 1) - free(mb_properties); -#endif - return (size_t)-1; - } + goto failure; beg += offset; /* Narrow down to the line containing the candidate, and run it through DFA. */ @@ -394,7 +388,7 @@ while (beg > buf && beg[-1] != eol) --beg; if (kwsm.index < kwset_exact_matches) - goto success; + goto success_in_beg_and_end; if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1) continue; } @@ -413,7 +407,7 @@ } /* Successful, no backreferences encountered! */ if (!backref) - goto success; + goto success_in_beg_and_end; } else end = beg + size; @@ -428,14 +422,11 @@ end - beg - 1, &(patterns[i].regs)))) { len = patterns[i].regs.end[0] - start; - if (exact) - { - *match_size = len; - return start; - } + if (exact && !match_words) + goto success_in_start_and_len; if ((!match_lines && !match_words) || (match_lines && len == end - beg - 1)) - goto success; + goto success_in_beg_and_end; /* If -w, check if the match aligns with word boundaries. We do this iteratively because: (a) the line may contain more than one occurence of the @@ -449,7 +440,7 @@ if ((start == 0 || !WCHAR ((unsigned char) beg[start - 1])) && (len == end - beg - 1 || !WCHAR ((unsigned char) beg[start + len]))) - goto success; + goto success_in_start_and_len; if (len > 0) { /* Try a shorter length anchored at the same place. */ @@ -476,19 +467,26 @@ } } /* for Regex patterns. */ } /* for (beg = end ..) */ + + failure: #ifdef MBS_SUPPORT if (MB_CUR_MAX > 1 && mb_properties) free (mb_properties); #endif /* MBS_SUPPORT */ return (size_t) -1; - success: + success_in_beg_and_end: + len = end - beg; + start = beg - buf; + /* FALLTHROUGH */ + + success_in_start_and_len: #ifdef MBS_SUPPORT - if (MB_CUR_MAX > 1 && mb_properties) - free (mb_properties); + if (MB_CUR_MAX > 1 && mb_properties) + free (mb_properties); #endif /* MBS_SUPPORT */ - *match_size = end - beg; - return beg - buf; + *match_size = len; + return start; } static void