summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorZefram <zefram@fysh.org>2012-02-25 15:41:17 +0000
committerZefram <zefram@fysh.org>2012-02-25 15:49:01 +0000
commit9100eeb186d403d6c6c6ef15844209cad5a9b9f0 (patch)
tree711e77c82c5995fd558d5b175490419a80ab43f3 /t
parent236cbe8d7a6747fb6144c93dd767895f8acffd00 (diff)
downloadperl-9100eeb186d403d6c6c6ef15844209cad5a9b9f0.tar.gz
delay allocating trans table until needed
Previously, a table was being allocated for OP_TRANS(|R), in a PVOP arrangement, as soon as the op was built. However, it wasn't used immediately, and for UTF8-flagged ops it would be thrown away, replaced by an SV-based translation table in a SVOP or PADOP arrangement. This mutation of the op structure occurred in pmtrans(), some time after original op building. If an error occurred before pmtrans(), requiring the op to be freed, op_clear() would be misled by the UTF8 flags into treating the PV as an SV or pad index, causing crashes in the latter case [perl #102858]. op_clear() was implicitly assuming that pmtrans() had been performed, due to lacking any explicit indication of the op's state of construction. Now, the PV table is allocated by pmtrans(), when it's actually going to populate it. The PV doesn't get allocated at all for UTF8-flagged ops. Prior to pmtrans(), the op_pv/op_sv/op_padix field is all bits zero, so there's no problem with freeing the op.
Diffstat (limited to 't')
-rw-r--r--t/op/tr.t11
1 files changed, 10 insertions, 1 deletions
diff --git a/t/op/tr.t b/t/op/tr.t
index 0f2ae97be6..5baa43178f 100644
--- a/t/op/tr.t
+++ b/t/op/tr.t
@@ -6,7 +6,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 128;
+plan tests => 130;
my $Is_EBCDIC = (ord('i') == 0x89 & ord('J') == 0xd1);
@@ -506,4 +506,13 @@ SKIP: {
is($x,"\x{143}", "utf8 + closure");
}
+# Freeing of trans ops prior to pmtrans() [perl #102858].
+eval q{ $a ~= tr/a/b/; };
+ok 1;
+SKIP: {
+ skip "no encoding", 1 unless eval { require encoding; 1 };
+ eval q{ use encoding "utf8"; $a ~= tr/a/b/; };
+ ok 1;
+}
+1;