summaryrefslogtreecommitdiff
path: root/regexec.c
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2007-02-02 14:37:31 +0000
committerNicholas Clark <nick@ccl4.org>2007-02-02 14:37:31 +0000
commit610460f93dd5a2665c479dc22acb80489faf9ce7 (patch)
tree6b025ad9cf71d3c12db7eb09431cb49273bdbd34 /regexec.c
parenteff3c707b45221807117761fc9b63fdb1798af5e (diff)
downloadperl-610460f93dd5a2665c479dc22acb80489faf9ce7.tar.gz
Change 29502 wasn't perfect - you need to remove any extra trailing
"\n" added by fbm_compile(), before recompiling with the same flags. In turn, to do that, it's best to store the flags even for short "PVBM"s. p4raw-id: //depot/perl@30092
Diffstat (limited to 'regexec.c')
-rw-r--r--regexec.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/regexec.c b/regexec.c
index 6c82ba7465..8697eb6281 100644
--- a/regexec.c
+++ b/regexec.c
@@ -5690,10 +5690,18 @@ S_to_utf8_substr(pTHX_ register regexp *prog)
SV* const sv = newSVsv(prog->substrs->data[i].substr);
prog->substrs->data[i].utf8_substr = sv;
sv_utf8_upgrade(sv);
- if (SvVALID(prog->substrs->data[i].substr))
- fbm_compile(sv, 0);
- if (SvTAIL(prog->substrs->data[i].substr))
- SvTAIL_on(sv);
+ if (SvVALID(prog->substrs->data[i].substr)) {
+ const U8 flags = BmFLAGS(prog->substrs->data[i].substr);
+ if (flags & FBMcf_TAIL) {
+ /* Trim the trailing \n that fbm_compile added last
+ time. */
+ SvCUR_set(sv, SvCUR(sv) - 1);
+ /* Whilst this makes the SV technically "invalid" (as its
+ buffer is no longer followed by "\0") when fbm_compile()
+ adds the "\n" back, a "\0" is restored. */
+ }
+ fbm_compile(sv, flags);
+ }
if (prog->substrs->data[i].substr == prog->check_substr)
prog->check_utf8 = sv;
}
@@ -5710,10 +5718,16 @@ S_to_byte_substr(pTHX_ register regexp *prog)
&& !prog->substrs->data[i].substr) {
SV* sv = newSVsv(prog->substrs->data[i].utf8_substr);
if (sv_utf8_downgrade(sv, TRUE)) {
- if (SvVALID(prog->substrs->data[i].utf8_substr))
- fbm_compile(sv, 0);
- if (SvTAIL(prog->substrs->data[i].utf8_substr))
- SvTAIL_on(sv);
+ if (SvVALID(prog->substrs->data[i].utf8_substr)) {
+ const U8 flags
+ = BmFLAGS(prog->substrs->data[i].utf8_substr);
+ if (flags & FBMcf_TAIL) {
+ /* Trim the trailing \n that fbm_compile added last
+ time. */
+ SvCUR_set(sv, SvCUR(sv) - 1);
+ }
+ fbm_compile(sv, flags);
+ }
} else {
SvREFCNT_dec(sv);
sv = &PL_sv_undef;