summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Mitchell <davem@fdisolutions.com>2005-04-21 15:36:14 +0000
committerDave Mitchell <davem@fdisolutions.com>2005-04-21 15:36:14 +0000
commitec0624293b57ae07d6b2c32bae099d4f163e7e07 (patch)
tree01d6b0ff58f43fa9a8d6808c0773376527f812a6
parenta9c4fd4eb137d3951b59e73b4474669240f974c1 (diff)
downloadperl-ec0624293b57ae07d6b2c32bae099d4f163e7e07.tar.gz
[perl #34976] substr uses utf8 length cache incorrectly
p4raw-id: //depot/perl@24270
-rw-r--r--sv.c2
-rwxr-xr-xt/op/substr.t9
2 files changed, 9 insertions, 2 deletions
diff --git a/sv.c b/sv.c
index f0a5a0f608..7bfd7a5083 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 9549d29028..2c6a0ed32e 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';
+}