From: Rafael Garcia-Suarez Date: Thu, 14 Feb 2002 23:58:00 +0000 (+0100) Subject: Re: bug? no warning from getc BOLLOCKS X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=90133b69afb5dccc00b1483d3839904e458ba347;p=p5sagit%2Fp5-mst-13.2.git Re: bug? no warning from getc BOLLOCKS Message-ID: <20020214235800.A12901@rafael> p4raw-id: //depot/perl@14695 --- diff --git a/pp_sys.c b/pp_sys.c index e7e4121..7ce9dae 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1134,7 +1134,7 @@ PP(pp_getc) { dSP; dTARGET; GV *gv; - IO *io; + IO *io = NULL; MAGIC *mg; if (MAXARG == 0) @@ -1157,8 +1157,11 @@ PP(pp_getc) SvSetMagicSV_nosteal(TARG, TOPs); RETURN; } - if (!gv || do_eof(gv)) /* make sure we have fp with something */ + if (!gv || do_eof(gv)) { /* make sure we have fp with something */ + if (ckWARN2(WARN_UNOPENED,WARN_CLOSED) && IoTYPE(io) != IoTYPE_WRONLY) + report_evil_fh(gv, io, PL_op->op_type); RETPUSHUNDEF; + } TAINT; sv_setpv(TARG, " "); *SvPVX(TARG) = PerlIO_getc(IoIFP(GvIOp(gv))); /* should never be EOF */ diff --git a/t/lib/warnings/pp_sys b/t/lib/warnings/pp_sys index 57abd69..5349f50 100644 --- a/t/lib/warnings/pp_sys +++ b/t/lib/warnings/pp_sys @@ -97,7 +97,11 @@ open(F, ">$file") ; my $a = sysread(F, $a,10) ; - lstat on filehandle %s [pp_lstat] + lstat on filehandle %s [pp_lstat] + + getc() on unopened filehandle [pp_getc] + + getc() on closed filehandle [pp_getc] __END__ # pp_sys.c [pp_untie] @@ -409,3 +413,15 @@ close $fh; EXPECT lstat() on filehandle STDIN at - line 3. lstat() on filehandle $fh at - line 5. +######## +# pp_sys.c [pp_getc] +use warnings qw(unopened closed) ; +getc FOO; +close STDIN; +getc STDIN; +no warnings qw(unopened closed) ; +getc FOO; +getc STDIN; +EXPECT +getc() on unopened filehandle FOO at - line 3. +getc() on closed filehandle STDIN at - line 5.