summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2002-02-08 01:21:07 +0100
committerJarkko Hietaniemi <jhi@iki.fi>2002-02-08 14:14:16 +0000
commited2c6b9b45ca155543a6a8e651e2d3e0d446406e (patch)
tree3d26bca888d8c378415b17a5d55fa709dd0169a7
parent327ccce1a786df11565e91b4bb4adc2762c13d28 (diff)
downloadperl-ed2c6b9b45ca155543a6a8e651e2d3e0d446406e.tar.gz
Re: [PATCH] eof() coredumps when ARGV is aliased to another filehandle
Message-ID: <20020208002107.E763@rafael> p4raw-id: //depot/perl@14601
-rw-r--r--doio.c2
-rw-r--r--pp_sys.c2
-rwxr-xr-xt/io/argv.t22
3 files changed, 22 insertions, 4 deletions
diff --git a/doio.c b/doio.c
index 68853c2d38..0520992cc7 100644
--- a/doio.c
+++ b/doio.c
@@ -997,7 +997,7 @@ Perl_do_eof(pTHX_ GV *gv)
PerlIO_set_cnt(IoIFP(io),-1);
}
if (PL_op->op_flags & OPf_SPECIAL) { /* not necessarily a real EOF yet? */
- if (!nextargv(PL_argvgv)) /* get another fp handy */
+ if (gv != PL_argvgv || !nextargv(gv)) /* get another fp handy */
return TRUE;
}
else
diff --git a/pp_sys.c b/pp_sys.c
index 4b1a1e7b9f..e7e41214ec 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1894,7 +1894,7 @@ PP(pp_eof)
if (MAXARG == 0) {
if (PL_op->op_flags & OPf_SPECIAL) { /* eof() */
IO *io;
- gv = PL_last_in_gv = PL_argvgv;
+ gv = PL_last_in_gv = GvEGV(PL_argvgv);
io = GvIO(gv);
if (io && !IoIFP(io)) {
if ((IoFLAGS(io) & IOf_START) && av_len(GvAVn(gv)) < 0) {
diff --git a/t/io/argv.t b/t/io/argv.t
index a602a02259..f2f3245b10 100755
--- a/t/io/argv.t
+++ b/t/io/argv.t
@@ -7,7 +7,7 @@ BEGIN {
require "./test.pl";
-plan(tests => 21);
+plan(tests => 22);
use File::Spec;
@@ -111,4 +111,22 @@ ok( eof(), 'eof() true after closing ARGV' );
close F or die "Could not close: $!";
}
-END { unlink 'Io_argv1.tmp', 'Io_argv1.tmp_bak', 'Io_argv2.tmp', 'Io_argv2.tmp_bak' }
+# This used to dump core
+fresh_perl_is( <<'**PROG**', "foobar", {}, "ARGV aliasing and eof()" );
+open OUT, ">Io_argv3.tmp" or die "Can't open temp file: $!";
+print OUT "foo";
+close OUT;
+open IN, "Io_argv3.tmp" or die "Can't open temp file: $!";
+*ARGV = *IN;
+while (<>) {
+ print;
+ print "bar" if eof();
+}
+close IN;
+unlink "Io_argv3.tmp";
+**PROG**
+
+END {
+ unlink 'Io_argv1.tmp', 'Io_argv1.tmp_bak',
+ 'Io_argv2.tmp', 'Io_argv2.tmp_bak', 'Io_argv3.tmp';
+}