Date: Sun, 11 Sep 2011 20:37:01 +0000 (UTC) From: Gabor Kovesdan <gabor@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r225491 - user/gabor/grep/trunk/regex Message-ID: <201109112037.p8BKb145094913@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gabor Date: Sun Sep 11 20:37:01 2011 New Revision: 225491 URL: http://svn.freebsd.org/changeset/base/225491 Log: - According to re_format(7) `^' and `$' are supposed to match null-string. Fix to match this behavior. Reported by: aakuusta@gmail.com Modified: user/gabor/grep/trunk/regex/tre-fastmatch.c Modified: user/gabor/grep/trunk/regex/tre-fastmatch.c ============================================================================== --- user/gabor/grep/trunk/regex/tre-fastmatch.c Sun Sep 11 20:25:57 2011 (r225490) +++ user/gabor/grep/trunk/regex/tre-fastmatch.c Sun Sep 11 20:37:01 2011 (r225491) @@ -406,10 +406,24 @@ static int fastcmp(const void *, const b fg->newline = (cflags & REG_NEWLINE); \ fg->nosub = (cflags & REG_NOSUB); \ \ + /* Cannot handle REG_ICASE with MB string */ \ + if (fg->icase && (TRE_MB_CUR_MAX > 1)) \ + { \ + DPRINT(("Cannot use fast matcher for MBS with REG_ICASE\n")); \ + return REG_BADPAT; \ + } + +#define CHECK_MATCHALL(literal) \ + if (!literal && n == 1 && pat[0] == TRE_CHAR('$')) \ + { \ + n--; \ + fg->eol = true; \ + } \ + \ if (n == 0) \ { \ fg->matchall = true; \ - fg->pattern = xmalloc(1); \ + fg->pattern = xmalloc(sizeof(char)); \ if (!fg->pattern) \ return REG_ESPACE; \ fg->pattern[0] = '\0'; \ @@ -422,13 +436,6 @@ static int fastcmp(const void *, const b fg->wpattern[0] = TRE_CHAR('\0'); \ DPRINT(("Matching every input\n")); \ return REG_OK; \ - } \ - \ - /* Cannot handle REG_ICASE with MB string */ \ - if (fg->icase && (TRE_MB_CUR_MAX > 1)) \ - { \ - DPRINT(("Cannot use fast matcher for MBS with REG_ICASE\n")); \ - return REG_BADPAT; \ } /* @@ -440,6 +447,8 @@ tre_compile_literal(fastmatch_t *fg, con { INIT_COMP; + CHECK_MATCHALL(true); + /* Cannot handle word boundaries with MB string */ if (fg->word && (TRE_MB_CUR_MAX > 1)) return REG_BADPAT; @@ -487,6 +496,8 @@ tre_compile_fast(fastmatch_t *fg, const pat++; } + CHECK_MATCHALL(false); + /* Handle word-boundary matching when GNU extensions are enabled */ if ((cflags & REG_GNU) && (n >= 14) && (memcmp(pat, TRE_CHAR("[[:<:]]"), 7 * sizeof(tre_char_t)) == 0) && @@ -759,7 +770,10 @@ tre_match_fast(const fastmatch_t *fg, co pmatch[0].rm_so = 0; pmatch[0].rm_eo = len; } - return REG_OK; + if (fg->bol && fg->eol) + return (len == 0) ? REG_OK : REG_NOMATCH; + else + return REG_OK; } /* No point in going farther if we do not have enough data. */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109112037.p8BKb145094913>