[perl #45337] utf8 + "[a]a{2}" + /$.../ = panic: sv_len_utf8 cache
Dave Mitchell [Fri, 14 Sep 2007 21:59:59 +0000 (21:59 +0000)]
when shrinking an SV, shrink the sv_len_utf8 cache too!

p4raw-id: //depot/perl@31867

regcomp.c
t/op/pat.t

index 358ac8e..441d762 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -3297,7 +3297,7 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp,
                                        SvUTF8(sv) && SvMAGICAL(sv) ?
                                        mg_find(sv, PERL_MAGIC_utf8) : NULL;
                                    if (mg && mg->mg_len >= 0)
-                                       mg->mg_len += CHR_SVLEN(last_str);
+                                       mg->mg_len += CHR_SVLEN(last_str) - l;
                                }
                                data->last_end += l * (mincount - 1);
                            }
index 536c6cd..00d00e7 100755 (executable)
@@ -4524,10 +4524,19 @@ ok($@=~/\QSequence \k... not terminated in regex;\E/);
     iseq($_,"!Bang!1!Bang!2!Bang!3!Bang!");
 }
 
+# [perl #45337] utf8 + "[a]a{2}" + /$.../ = panic: sv_len_utf8 cache
+
+{
+    local ${^UTF8CACHE} = -1;
+    my $s="[a]a{2}";
+    utf8::upgrade $s;
+    ok("aaa" =~ /$s/, "#45337");
+}
+
 # Put new tests above the dotted line about a page above this comment
 iseq(0+$::test,$::TestCount,"Got the right number of tests!");
 # Don't forget to update this!
 BEGIN {
-    $::TestCount = 1963;
+    $::TestCount = 1964;
     print "1..$::TestCount\n";
 }