From owner-svn-src-user@FreeBSD.ORG Thu Aug 25 00:55:19 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ADF751065672; Thu, 25 Aug 2011 00:55:19 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 941788FC0C; Thu, 25 Aug 2011 00:55:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7P0tJTj077698; Thu, 25 Aug 2011 00:55:19 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7P0tJxG077695; Thu, 25 Aug 2011 00:55:19 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108250055.p7P0tJxG077695@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 25 Aug 2011 00:55:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225159 - user/gabor/tre-integration/contrib/tre/lib X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 25 Aug 2011 00:55:19 -0000 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) \