Commit f87d2a76ea for perl
commit f87d2a76eaf72e08681f633df506a64b6d0fc651
Author: Richard Leach <rich+perl@hyphen-dash-hyphen.info>
Date: Wed Nov 4 13:58:36 2026 +0000
pp_subst: only call GETMAGIC once on TARG
A double `FETCH` was possible when the target of the operation was
something other than a simple scalar string.
(Spotted by a Claude code review of the working branch.)
diff --git a/pp_hot.c b/pp_hot.c
index b52fd2f179..4ae893cd74 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -5681,7 +5681,10 @@ PP(pp_subst)
However, I suspect it isn't worth the complexity of
unravelling the C<goto force_it> for the small number of
cases where it would be viable to drop into the copy code. */
- TARG = sv_mortalcopy_flags(TARG, SV_GMAGIC|SV_NOSTEAL);
+
+ /* Note: GMAGIC check should have already occurred, prior to
+ * earlier COW check. Don't double-GET. */
+ TARG = sv_mortalcopy_flags(TARG, SV_NOSTEAL);
}
orig = SvPV_force_nomg(TARG, len);
goto force_it;
diff --git a/t/op/tie_fetch_count.t b/t/op/tie_fetch_count.t
index 862e502c34..ec256ecc75 100644
--- a/t/op/tie_fetch_count.t
+++ b/t/op/tie_fetch_count.t
@@ -9,7 +9,7 @@ BEGIN {
set_up_inc('../lib');
}
-plan (tests => 347);
+plan (tests => 350);
use strict;
use warnings;
@@ -342,6 +342,16 @@ substr$var1,0,0,"\x{100}"; check_count '4-arg substr with utf8 replacement';
untie $@;
}
+{
+ no warnings 'uninitialized';
+ tie $var, "main", undef;
+ $dummy = $var =~ s/^/x/r; check_count 's///r on undef';
+}
+tie $var, "main", v1.2.3;
+$dummy = $var =~ s/^/x/r; check_count 's///r on v-string';
+tie $var, "main", *dummy;
+$dummy = $var =~ s/^/x/r; check_count 's///r on glob';
+
###############################################
# Tests for $foo binop $foo #
###############################################