diff options
-rw-r--r-- | doio.c | 6 | ||||
-rw-r--r-- | t/op/filetest.t | 29 |
2 files changed, 32 insertions, 3 deletions
@@ -1286,12 +1286,14 @@ Perl_my_stat_flags(pTHX_ const U32 flags) } else if (IoDIRP(io)) { return (PL_laststatval = PerlLIO_fstat(my_dirfd(IoDIRP(io)), &PL_statcache)); } else { + PL_laststatval = -1; report_evil_fh(gv); - return (PL_laststatval = -1); + return -1; } } else { + PL_laststatval = -1; report_evil_fh(gv); - return (PL_laststatval = -1); + return -1; } } else if (PL_op->op_private & OPpFT_STACKED) { diff --git a/t/op/filetest.t b/t/op/filetest.t index 9e46823244..cf7a02dae4 100644 --- a/t/op/filetest.t +++ b/t/op/filetest.t @@ -10,7 +10,7 @@ BEGIN { } use Config; -plan(tests => 40 + 27*14); +plan(tests => 42 + 27*14); ok( -d 'op' ); ok( -f 'TEST' ); @@ -291,3 +291,30 @@ SKIP: { is runperl(prog => '-T _', switches => ['-w'], stderr => 1), "", 'no uninit warnings from -T with no preceding stat'; + +# Unsuccessful filetests on filehandles should leave stat buffers in the +# same state whether fatal warnings are on or off. +{ + stat "test.pl"; + # This GV has no IO + -r *phlon; + my $failed_stat1 = stat _; + + stat "test.pl"; + eval { use warnings FATAL => unopened; -r *phlon }; + my $failed_stat2 = stat _; + + is $failed_stat2, $failed_stat1, + 'failed -r($gv_without_io) with and w/out fatal warnings'; + + stat "test.pl"; + -r cength; # at compile time autovivifies IO, but with no fp + $failed_stat1 = stat _; + + stat "test.pl"; + eval { use warnings FATAL => unopened; -r cength }; + $failed_stat2 = stat _; + + is $failed_stat2, $failed_stat1, + 'failed -r($gv_with_io_but_no_fp) with and w/out fatal warnings'; +} |