svn commit: r225159 - user/gabor/tre-integration/contrib/tre/lib
Gabor Kovesdan
gabor at FreeBSD.org
Thu Aug 25 00:55:19 UTC 2011
Author: gabor
Date: Thu Aug 25 00:55:19 2011
New Revision: 225159
URL: http://svn.freebsd.org/changeset/base/225159
Log:
- Only compile shortcut if length is at least 2
- Still, fix segfault in fast matcher when len == 1 because this code may
be used independently through the public interface
Modified:
user/gabor/tre-integration/contrib/tre/lib/tre-compile.c
user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c
Modified: user/gabor/tre-integration/contrib/tre/lib/tre-compile.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-compile.c Thu Aug 25 00:25:15 2011 (r225158)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-compile.c Thu Aug 25 00:55:19 2011 (r225159)
@@ -1873,25 +1873,31 @@ tre_compile(regex_t *preg, const tre_cha
/* Parse context. */
tre_parse_ctx_t parse_ctx;
- /* Check if we can cheat with a fixed string algorithm. */
- shortcut = xmalloc(sizeof(fastmatch_t));
- if (!shortcut)
- return REG_ESPACE;
- ret = (cflags & REG_LITERAL)
- ? tre_compile_literal(shortcut, regex, n, cflags)
- : tre_compile_fast(shortcut, regex, n, cflags);
- if (ret == REG_OK)
- {
- preg->shortcut = shortcut;
- preg->re_nsub = 0;
- DPRINT("tre_compile: pattern compiled for fast matcher\n");
- return REG_OK;
- }
- else
+ /*
+ * Check if we can cheat with a fixed string algorithm
+ * if the pattern is long enough.
+ */
+ if (n >= 2)
{
- xfree(shortcut);
- preg->shortcut = NULL;
- DPRINT("tre_compile: pattern compilation failed for fast matcher\n");
+ shortcut = xmalloc(sizeof(fastmatch_t));
+ if (!shortcut)
+ return REG_ESPACE;
+ ret = (cflags & REG_LITERAL)
+ ? tre_compile_literal(shortcut, regex, n, cflags)
+ : tre_compile_fast(shortcut, regex, n, cflags);
+ if (ret == REG_OK)
+ {
+ preg->shortcut = shortcut;
+ preg->re_nsub = 0;
+ DPRINT("tre_compile: pattern compiled for fast matcher\n");
+ return REG_OK;
+ }
+ else
+ {
+ xfree(shortcut);
+ preg->shortcut = NULL;
+ DPRINT("tre_compile: pattern compilation failed for fast matcher\n");
+ }
}
/* Allocate a stack used throughout the compilation process for various
Modified: user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c
==============================================================================
--- user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Thu Aug 25 00:25:15 2011 (r225158)
+++ user/gabor/tre-integration/contrib/tre/lib/tre-fastmatch.c Thu Aug 25 00:55:19 2011 (r225159)
@@ -265,7 +265,10 @@ static int fastcmp(const void *, const v
fg->sbmGs = xmalloc(fg->len * sizeof(int)); \
if (!fg->sbmGs) \
return REG_ESPACE; \
- _FILL_BMGS(fg->sbmGs, fg->pattern, fg->len, false); \
+ if (fg->len == 1) \
+ fg->sbmGs[0] = 1; \
+ else \
+ _FILL_BMGS(fg->sbmGs, fg->pattern, fg->len, false); \
}
/*
@@ -277,7 +280,10 @@ static int fastcmp(const void *, const v
fg->bmGs = xmalloc(fg->wlen * sizeof(int)); \
if (!fg->bmGs) \
return REG_ESPACE; \
- _FILL_BMGS(fg->bmGs, fg->wpattern, fg->wlen, true); \
+ if (fg->wlen == 1) \
+ fg->bmGs[0] = 1; \
+ else \
+ _FILL_BMGS(fg->bmGs, fg->wpattern, fg->wlen, true); \
}
#define _FILL_BMGS(arr, pat, plen, wide) \
More information about the svn-src-user
mailing list