summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doop.c1
-rw-r--r--t/op/tr.t10
2 files changed, 9 insertions, 2 deletions
diff --git a/doop.c b/doop.c
index faf74c59a8..5a819a7f52 100644
--- a/doop.c
+++ b/doop.c
@@ -632,7 +632,6 @@ Perl_do_trans(pTHX_ SV *sv)
PERL_ARGS_ASSERT_DO_TRANS;
if (SvREADONLY(sv) && !(PL_op->op_private & OPpTRANS_IDENTICAL)) {
- if (!SvIsCOW(sv))
Perl_croak_no_modify();
}
(void)SvPV_const(sv, len);
diff --git a/t/op/tr.t b/t/op/tr.t
index 53530f2f04..55a343861d 100644
--- a/t/op/tr.t
+++ b/t/op/tr.t
@@ -8,7 +8,7 @@ BEGIN {
require './test.pl';
}
-plan tests => 132;
+plan tests => 134;
my $Is_EBCDIC = (ord('i') == 0x89 & ord('J') == 0xd1);
@@ -526,4 +526,12 @@ SKIP: {
is($x, "PerlĪ²", "Only first of multiple transliterations is used");
}
+# tr/a/b/ should fail even on zero-length read-only strings
+use constant nullrocow => (keys%{{""=>undef}})[0];
+for ("", nullrocow) {
+ eval { $_ =~ y/a/b/ };
+ like $@, qr/^Modification of a read-only value attempted at /,
+ 'tr/a/b/ fails on zero-length ro string';
+}
+
1;