Module Name: src
Committed By: rin
Date: Sun Nov 19 13:00:31 UTC 2017
Modified Files:
src/external/bsd/tre/dist/lib: regexec.c
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/external/bsd/tre/dist/lib/regexec.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/bsd/tre/dist/lib/regexec.c
diff -u src/external/bsd/tre/dist/lib/regexec.c:1.9 src/external/bsd/tre/dist/lib/regexec.c:1.10
--- src/external/bsd/tre/dist/lib/regexec.c:1.9 Fri Nov 17 16:16:19 2017
+++ src/external/bsd/tre/dist/lib/regexec.c Sun Nov 19 13:00:31 2017
@@ -43,8 +43,11 @@ tre_fill_pmatch(size_t nmatch, regmatch_
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 @@ tre_match(const tre_tnfa_t *tnfa, const
{
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 @@ tre_match_approx(const tre_tnfa_t *tnfa,
{
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 @@ tre_match_approx(const tre_tnfa_t *tnfa,
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);