From owner-svn-src-user@FreeBSD.ORG Thu Jun 2 14:00:32 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 7D22B106564A; Thu, 2 Jun 2011 14:00:32 +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 54EB88FC17; Thu, 2 Jun 2011 14:00:32 +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 p52E0WD2020174; Thu, 2 Jun 2011 14:00:32 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p52E0W4i020172; Thu, 2 Jun 2011 14:00:32 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201106021400.p52E0W4i020172@svn.freebsd.org> From: Gabor Kovesdan Date: Thu, 2 Jun 2011 14:00:32 +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: r222608 - 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, 02 Jun 2011 14:00:32 -0000 Author: gabor Date: Thu Jun 2 14:00:31 2011 New Revision: 222608 URL: http://svn.freebsd.org/changeset/base/222608 Log: - Fix REG_STARTEND and avoid copying the input string Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c Modified: user/gabor/tre-integration/contrib/tre/lib/regexec.c ============================================================================== --- user/gabor/tre-integration/contrib/tre/lib/regexec.c Thu Jun 2 13:57:49 2011 (r222607) +++ user/gabor/tre-integration/contrib/tre/lib/regexec.c Thu Jun 2 14:00:31 2011 (r222608) @@ -209,18 +209,16 @@ tre_regnexec(const regex_t *preg, const if (eflags & REG_STARTEND) { - off_t s_off = pmatch[0].rm_so; - off_t e_off = pmatch[0].rm_eo; - size_t slen = e_off - s_off; - char *sstr = xmalloc(slen); - strncpy(sstr, &str[s_off], slen); - int ret = tre_match(tnfa, sstr, slen, type, nmatch, pmatch, eflags); + size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so); + size_t offset = pmatch[0].rm_so; + str = &str[offset]; + int ret = tre_match(tnfa, str, slen, type, nmatch, pmatch, eflags); if (!(eflags & REG_NOSUB)) { for (unsigned i = 0; i < nmatch; i++) { - pmatch[i].rm_so += slen; - pmatch[i].rm_eo += slen; + pmatch[i].rm_so += offset; + pmatch[i].rm_eo += offset; } } return ret; @@ -249,18 +247,16 @@ tre_regwnexec(const regex_t *preg, const if (eflags & REG_STARTEND) { - off_t s_off = pmatch[0].rm_so; - off_t e_off = pmatch[0].rm_eo; - size_t slen = e_off - s_off; - wchar_t *sstr = xmalloc(slen * sizeof(wint_t)); - wcsncpy(sstr, &str[s_off], slen); - int ret = tre_match(tnfa, sstr, slen, STR_WIDE, nmatch, pmatch, eflags); + size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so); + size_t offset = pmatch[0].rm_so; + str = &str[offset]; + int ret = tre_match(tnfa, str, slen, STR_WIDE, nmatch, pmatch, eflags); if (!(eflags & REG_NOSUB)) { for (unsigned i = 0; i < nmatch; i++) { - pmatch[i].rm_so += slen; - pmatch[i].rm_eo += slen; + pmatch[i].rm_so += offset; + pmatch[i].rm_eo += offset; } } return ret;