Skip to content

Commit f4c6177

Browse files
committed
mess_sv(): access only if PL_curcop is non-null
RT #130621 In Perl_mess_sv(), don't try to add an "at foo line NN" to the error message if PL_curcop is null. In the ticket above, the reason that PL_curcop is null is the less than optimal way that evals free their optree: ideally the optree should be attached to the eval CV and freed when the CV is; instead a separate SAVEFREEOP() is done. But that fix is for another time; regardless, mess_sv() should have a PL_curcop != NULL guard anyway.
1 parent b1a69a6 commit f4c6177

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

util.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,14 +1518,17 @@ Perl_mess_sv(pTHX_ SV *basemsg, bool consume)
15181518
* from the sibling of PL_curcop.
15191519
*/
15201520

1521-
const COP *cop =
1522-
closest_cop(PL_curcop, OpSIBLING(PL_curcop), PL_op, FALSE);
1523-
if (!cop)
1524-
cop = PL_curcop;
1525-
1526-
if (CopLINE(cop))
1527-
Perl_sv_catpvf(aTHX_ sv, " at %s line %" IVdf,
1528-
OutCopFILE(cop), (IV)CopLINE(cop));
1521+
if (PL_curcop) {
1522+
const COP *cop =
1523+
closest_cop(PL_curcop, OpSIBLING(PL_curcop), PL_op, FALSE);
1524+
if (!cop)
1525+
cop = PL_curcop;
1526+
1527+
if (CopLINE(cop))
1528+
Perl_sv_catpvf(aTHX_ sv, " at %s line %" IVdf,
1529+
OutCopFILE(cop), (IV)CopLINE(cop));
1530+
}
1531+
15291532
/* Seems that GvIO() can be untrustworthy during global destruction. */
15301533
if (GvIO(PL_last_in_gv) && (SvTYPE(GvIOp(PL_last_in_gv)) == SVt_PVIO)
15311534
&& IoLINES(GvIOp(PL_last_in_gv)))

0 commit comments

Comments
 (0)