summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2020-04-01 06:05:06 -0600
committerKarl Williamson <khw@cpan.org>2020-04-02 09:17:38 -0600
commit9f31bc5d8d184ee704d37590d4271ea43374c6c8 (patch)
treec96da89ee686169982cffc31aea0aa512aa75597 /t
parent8bbdcb372d98806ff15f6de9ae9f263b85265432 (diff)
downloadperl-9f31bc5d8d184ee704d37590d4271ea43374c6c8.tar.gz
tr/abc/de/: Properly handle longer lhs in in-place calc
A tr/// can be done in-place if the target string doesn't contain a character whose transliterated representation is longer than the original. Otherwise, writing the new value would destroy the next character we need to read. In general, we can't know if a particular string contains such a character without keeping a list of the problematic characters, and scanning it ahead of time for occurrences of those. Instead, we determine at compilation time if, for a given transliteration, if there exists any possible target string that could have an overwriting problem. If none exist, we edit in place. Otherwise, we first make a copy. Prior to this commit, the code failed to account for the case where the rhs is shorter than the left, so that any unmatched lhs characters map to the final rhs one. The reason the code didn't consider this is that I didn't think of this possibility when writing it. This fixes #17654 and #17643
Diffstat (limited to 't')
-rw-r--r--t/op/tr.t8
1 files changed, 7 insertions, 1 deletions
diff --git a/t/op/tr.t b/t/op/tr.t
index c5a33c772e..cabcac65ac 100644
--- a/t/op/tr.t
+++ b/t/op/tr.t
@@ -13,7 +13,7 @@ BEGIN {
use utf8;
-plan tests => 314;
+plan tests => 315;
# Test this first before we extend the stack with other operations.
# This caused an asan failure due to a bad write past the end of the stack.
@@ -1187,4 +1187,10 @@ for ("", nullrocow) {
is($d, "\x{105}", '104 -> 105');
}
+{
+ my $c = "cb";
+ eval '$c =~ tr{aabc}{d\x{d0000}}';
+ is($c, "\x{d0000}\x{d0000}", "Shouldn't generate valgrind errors");
+}
+
1;