From 5e42f66b6197344bd46a9aaba91f6542f3ebb156 Mon Sep 17 00:00:00 2001 From: bulk88 Date: Wed, 28 May 2025 04:28:30 -0400 Subject: [PATCH] scope.c S_save_scalar_at() pick right type from the start -type PVGV and GV* API will eventually SEGV through GvNAME and PP tie so bounds limit it to the 2 scalar string types, that are capable of MG and not any other higher order aggregate types --- scope.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scope.c b/scope.c index b8063c27760b..c718ea4b9ef8 100644 --- a/scope.c +++ b/scope.c @@ -309,8 +309,11 @@ S_save_scalar_at(pTHX_ SV **sptr, const U32 flags) if (flags & SAVEf_KEEPOLDELEM) sv = osv; else { - sv = (*sptr = newSV_type(SVt_NULL)); - if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv)) + U8 old_type = SvTYPE(osv); + bool is_mg = old_type >= SVt_PVMG && SvMAGIC(osv); + sv = (*sptr = newSV_type(is_mg && /* GV*s can't circulate with all nulls */ + (old_type == SVt_PVMG || old_type == SVt_PVLV) ? old_type : SVt_NULL)); + if (is_mg) mg_localize(osv, sv, cBOOL(flags & SAVEf_SETMAGIC)); }