svn commit: r225491 - user/gabor/grep/trunk/regex
Gabor Kovesdan
gabor at FreeBSD.org
Sun Sep 11 20:37:02 UTC 2011
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 at 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. */
More information about the svn-src-user
mailing list