From: Jarkko Hietaniemi Date: Thu, 21 Dec 2000 03:54:11 +0000 (+0000) Subject: Fix for 20001210.003, "write(FH) on closed FH causes segv". X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7ef822cddfe985045cd287429915d6f6aecd27c9;p=p5sagit%2Fp5-mst-13.2.git Fix for 20001210.003, "write(FH) on closed FH causes segv". p4raw-id: //depot/perl@8214 --- diff --git a/pp_sys.c b/pp_sys.c index c1857ae..fe914f3 100644 --- a/pp_sys.c +++ b/pp_sys.c @@ -1236,6 +1236,8 @@ PP(pp_leavewrite) DEBUG_f(PerlIO_printf(Perl_debug_log, "left=%ld, todo=%ld\n", (long)IoLINES_LEFT(io), (long)FmLINES(PL_formtarget))); + if (!io || !ofp) + goto forget_top; if (IoLINES_LEFT(io) < FmLINES(PL_formtarget) && PL_formtarget != PL_toptarget) { @@ -1356,6 +1358,7 @@ PP(pp_leavewrite) PUSHs(&PL_sv_yes); } } +bad_ofp: PL_formtarget = PL_bodytarget; PUTBACK; return pop_return(); diff --git a/t/op/misc.t b/t/op/misc.t index 0db36c9..805a32b 100755 --- a/t/op/misc.t +++ b/t/op/misc.t @@ -600,3 +600,20 @@ die qr(x) EXPECT (?-xism:x) at - line 1. ######## +# 20001210.003 mjd@plover.com +format REMITOUT_TOP = +FOO +. + +format REMITOUT = +BAR +. + +# This loop causes a segv in 5.6.0 +for $lineno (1..61) { + write REMITOUT; +} + +print "It's OK!"; +EXPECT +It's OK!