Skip to content

Commit 5e42f66

Browse files
committed
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
1 parent 69b5e8a commit 5e42f66

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

scope.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,11 @@ S_save_scalar_at(pTHX_ SV **sptr, const U32 flags)
309309
if (flags & SAVEf_KEEPOLDELEM)
310310
sv = osv;
311311
else {
312-
sv = (*sptr = newSV_type(SVt_NULL));
313-
if (SvTYPE(osv) >= SVt_PVMG && SvMAGIC(osv))
312+
U8 old_type = SvTYPE(osv);
313+
bool is_mg = old_type >= SVt_PVMG && SvMAGIC(osv);
314+
sv = (*sptr = newSV_type(is_mg && /* GV*s can't circulate with all nulls */
315+
(old_type == SVt_PVMG || old_type == SVt_PVLV) ? old_type : SVt_NULL));
316+
if (is_mg)
314317
mg_localize(osv, sv, cBOOL(flags & SAVEf_SETMAGIC));
315318
}
316319

0 commit comments

Comments
 (0)