From owner-svn-src-user@FreeBSD.ORG Sun Sep 11 20:37:02 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 3C3071065689; Sun, 11 Sep 2011 20:37:02 +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 13AD88FC08; Sun, 11 Sep 2011 20:37:02 +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 p8BKb1ZQ094915; Sun, 11 Sep 2011 20:37:01 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p8BKb145094913; Sun, 11 Sep 2011 20:37:01 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201109112037.p8BKb145094913@svn.freebsd.org> From: Gabor Kovesdan Date: Sun, 11 Sep 2011 20:37:01 +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: r225491 - user/gabor/grep/trunk/regex 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: Sun, 11 Sep 2011 20:37:02 -0000 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. */