From: Adrian M. Enache Date: Thu, 11 Dec 2003 20:11:07 +0000 (+0000) Subject: fix bug #24605. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8f78557a961555c7d3a0f903d990f4f78b07624a;p=p5sagit%2Fp5-mst-13.2.git fix bug #24605. substr() wasn't working when used repeatedly on the same utf-8 string. p4raw-id: //depot/perl@21875 --- diff --git a/sv.c b/sv.c index 6f53c58..40d99cb 100644 --- a/sv.c +++ b/sv.c @@ -5735,10 +5735,8 @@ S_utf8_mg_pos_init(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i, I32 *offse bool found = FALSE; if (SvMAGICAL(sv) && !SvREADONLY(sv)) { - if (!*mgp) { - sv_magic(sv, 0, PERL_MAGIC_utf8, 0, 0); - *mgp = mg_find(sv, PERL_MAGIC_utf8); - } + if (!*mgp) + *mgp = sv_magicext(sv, 0, PERL_MAGIC_utf8, &PL_vtbl_utf8, 0, 0); assert(*mgp); if ((*mgp)->mg_ptr) @@ -5831,6 +5829,12 @@ S_utf8_mg_pos(pTHX_ SV *sv, MAGIC **mgp, STRLEN **cachep, I32 i, I32 *offsetp, I /* Update the cache. */ (*cachep)[i] = (STRLEN)uoff; (*cachep)[i+1] = p - start; + + /* Drop the stale "length" cache */ + if (i == 0) { + (*cachep)[2] = 0; + (*cachep)[3] = 0; + } found = TRUE; } diff --git a/t/op/substr.t b/t/op/substr.t index 533f1a5..dfb483a 100755 --- a/t/op/substr.t +++ b/t/op/substr.t @@ -1,6 +1,6 @@ #!./perl -print "1..176\n"; +print "1..177\n"; #P = start of string Q = start of substr R = end of substr S = end of string @@ -602,3 +602,10 @@ ok 174, $x eq "\x{100}\x{200}\xFFb"; my $x = my $y = 'AB'; ss $x; ss $y; ok 176, $x eq $y; } + +# [perl #24605] +{ + my $x = "0123456789\x{500}"; + my $y = substr $x, 4; + ok 177, substr($x, 7, 1) eq "7"; +}