summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-08-21 19:07:22 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-08-21 19:07:22 +0000
commit0daa599b568c3d2373a59e6063e86a6f865719a8 (patch)
tree0965e5bd5675d5a71cac10d4e1ca1e6f9d27bb1c /mg.c
parent965cd7038b700c7c8e135d0b7ad9fbadc532cee3 (diff)
downloadperl-0daa599b568c3d2373a59e6063e86a6f865719a8.tar.gz
The magic variables that alter STDOUT have a tendancy to segfault
when accessed if STDOUT is undefined. Protect them. p4raw-id: //depot/perl@20809
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/mg.c b/mg.c
index 8a40a76ea5..d298176481 100644
--- a/mg.c
+++ b/mg.c
@@ -805,7 +805,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
}
break;
case '^':
- s = IoTOP_NAME(GvIOp(PL_defoutgv));
+ if (GvIOp(PL_defoutgv))
+ s = IoTOP_NAME(GvIOp(PL_defoutgv));
if (s)
sv_setpv(sv,s);
else {
@@ -814,20 +815,24 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
}
break;
case '~':
- s = IoFMT_NAME(GvIOp(PL_defoutgv));
+ if (GvIOp(PL_defoutgv))
+ s = IoFMT_NAME(GvIOp(PL_defoutgv));
if (!s)
s = GvENAME(PL_defoutgv);
sv_setpv(sv,s);
break;
#ifndef lint
case '=':
- sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv)));
+ if (GvIOp(PL_defoutgv))
+ sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(PL_defoutgv)));
break;
case '-':
- sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv)));
+ if (GvIOp(PL_defoutgv))
+ sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(PL_defoutgv)));
break;
case '%':
- sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv)));
+ if (GvIOp(PL_defoutgv))
+ sv_setiv(sv, (IV)IoPAGE(GvIOp(PL_defoutgv)));
break;
#endif
case ':':
@@ -838,7 +843,8 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
WITH_THR(sv_setiv(sv, (IV)PL_curcop->cop_arybase));
break;
case '|':
- sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
+ if (GvIOp(PL_defoutgv))
+ sv_setiv(sv, (IV)(IoFLAGS(GvIOp(PL_defoutgv)) & IOf_FLUSH) != 0 );
break;
case ',':
break;