summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-01-31 12:57:09 -0800
committerFather Chrysostomos <sprout@cpan.org>2012-01-31 12:57:09 -0800
commitfe46cbda823c09f80e4bc48dd93fafb26cc805f6 (patch)
tree0a31624d53759263953496dec82595cc9edaf9d2 /sv.c
parent92c88ef1fd925fb1c768293bd43deb970990e7f3 (diff)
downloadperl-fe46cbda823c09f80e4bc48dd93fafb26cc805f6.tar.gz
[perl #108994] Stop SvPVutf8 from coercing SVs
In shouldn’t destroy globs or references passed to it, or try to coerce them if they are read-only or incoercible. I added tests for SvPVbyte at the same time, even though it was not exhibiting the same problems, as sv_utf8_downgrade doesn’t try to coerce anything. (SvPVbyte has its own set of bugs, which I hope to fix in fifthcoming commits.)
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/sv.c b/sv.c
index be5aec808c..4b37aabbff 100644
--- a/sv.c
+++ b/sv.c
@@ -3050,10 +3050,12 @@ Usually accessed via the C<SvPVutf8> macro.
*/
char *
-Perl_sv_2pvutf8(pTHX_ register SV *const sv, STRLEN *const lp)
+Perl_sv_2pvutf8(pTHX_ register SV *sv, STRLEN *const lp)
{
PERL_ARGS_ASSERT_SV_2PVUTF8;
+ if ((SvTHINKFIRST(sv) && !SvIsCOW(sv)) || isGV_with_GP(sv))
+ sv = sv_mortalcopy(sv);
sv_utf8_upgrade(sv);
return lp ? SvPV(sv,*lp) : SvPV_nolen(sv);
}