Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/tre/dist/lib nmatch and pmatch should be ignore...



details:   https://anonhg.NetBSD.org/src/rev/f9e2e9836c49
branches:  trunk
changeset: 357639:f9e2e9836c49
user:      rin <rin%NetBSD.org@localhost>
date:      Sun Nov 19 13:00:31 2017 +0000

description:
nmatch and pmatch should be ignored when regex was compiled with REG_NOSUB,
partially taken from musl libc:
https://git.musl-libc.org/cgit/musl/commit/src/regex/regexec.c?id=72ed3d47e567b1635a35d3c1d174c8a8b2787e30

diffstat:

 external/bsd/tre/dist/lib/regexec.c |  18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diffs (62 lines):

diff -r e57b48d6107a -r f9e2e9836c49 external/bsd/tre/dist/lib/regexec.c
--- a/external/bsd/tre/dist/lib/regexec.c       Sun Nov 19 12:35:39 2017 +0000
+++ b/external/bsd/tre/dist/lib/regexec.c       Sun Nov 19 13:00:31 2017 +0000
@@ -43,8 +43,11 @@
   unsigned int i, j;
   int *parents;
 
+  if (cflags & REG_NOSUB)
+    return;
+
   i = 0;
-  if (match_eo >= 0 && !(cflags & REG_NOSUB))
+  if (match_eo >= 0)
     {
       /* Construct submatch offsets from the tags. */
       DPRINT(("end tag = t%d = %d\n", tnfa->end_tag, match_eo));
@@ -127,6 +130,7 @@
 {
   reg_errcode_t status;
   int *tags = NULL, eo;
+  if (tnfa->cflags & REG_NOSUB) nmatch = 0;
   if (tnfa->num_tags > 0 && nmatch > 0)
     {
 #ifdef TRE_USE_ALLOCA
@@ -315,20 +319,26 @@
 {
   reg_errcode_t status;
   int *tags = NULL, eo;
+  size_t nmatch;
+
+  if (tnfa->cflags & REG_NOSUB)
+    nmatch = 0;
+  else
+    nmatch = match->nmatch;
 
   /* If the regexp does not use approximate matching features, the
      maximum cost is zero, and the approximate matcher isn't forced,
      use the exact matcher instead. */
   if (params.max_cost == 0 && !tnfa->have_approx
       && !(eflags & REG_APPROX_MATCHER))
-    return tre_match(tnfa, string, len, type, match->nmatch, match->pmatch,
+    return tre_match(tnfa, string, len, type, nmatch, match->pmatch,
                     eflags);
 
   /* Back references are not supported by the approximate matcher. */
   if (tnfa->have_backrefs)
     return REG_BADPAT;
 
-  if (tnfa->num_tags > 0 && match->nmatch > 0)
+  if (tnfa->num_tags > 0 && nmatch > 0)
     {
 #if TRE_USE_ALLOCA
       tags = alloca(sizeof(*tags) * tnfa->num_tags);
@@ -341,7 +351,7 @@
   status = tre_tnfa_run_approx(tnfa, string, (int)len, type, tags,
                               match, params, eflags, &eo);
   if (status == REG_OK)
-    tre_fill_pmatch(match->nmatch, match->pmatch, tnfa->cflags, tnfa, tags, eo);
+    tre_fill_pmatch(nmatch, match->pmatch, tnfa->cflags, tnfa, tags, eo);
 #ifndef TRE_USE_ALLOCA
   if (tags)
     xfree(tags);



Home | Main Index | Thread Index | Old Index