From: Dave Mitchell Date: Thu, 21 Apr 2005 15:36:14 +0000 (+0000) Subject: [perl #34976] substr uses utf8 length cache incorrectly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ec0624293b57ae07d6b2c32bae099d4f163e7e07;p=p5sagit%2Fp5-mst-13.2.git [perl #34976] substr uses utf8 length cache incorrectly p4raw-id: //depot/perl@24270 --- diff --git a/sv.c b/sv.c index f0a5a0f..7bfd7a5 100644 --- a/sv.c +++ b/sv.c @@ -6402,7 +6402,7 @@ Perl_sv_pos_u2b(pTHX_ register SV *sv, I32* offsetp, I32* lenp) if (lenp) { found = FALSE; start = s; - if (utf8_mg_pos(sv, &mg, &cache, 2, lenp, *lenp + *offsetp, &s, start, send)) { + if (utf8_mg_pos(sv, &mg, &cache, 2, lenp, *lenp, &s, start, send)) { *lenp -= boffset; found = TRUE; } diff --git a/t/op/substr.t b/t/op/substr.t index 9549d29..2c6a0ed 100755 --- a/t/op/substr.t +++ b/t/op/substr.t @@ -1,6 +1,6 @@ #!./perl -print "1..190\n"; +print "1..192\n"; #P = start of string Q = start of substr R = end of substr S = end of string @@ -658,3 +658,10 @@ ok 174, $x eq "\x{100}\x{200}\xFFb"; substr($a, -1) &= chr(0xfeff); ok 190, $a eq "\xbf"; } + +# [perl #34976] incorrect caching of utf8 substr length +{ + my $a = "abcd\x{100}"; + ok 191, substr($a,1,2) eq 'bc'; + ok 192, substr($a,1,1) eq 'b'; +}