Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 2 Jun 2011 14:00:32 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r222608 - user/gabor/tre-integration/contrib/tre/lib
Message-ID:  <201106021400.p52E0W4i020172@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201106021400.p52E0W4i020172>