From: Rafael Garcia-Suarez Date: Thu, 30 Sep 2004 15:12:29 +0000 (+0000) Subject: A fix for [perl #31692] : as PerlIO::scalar accesses directly the X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=47cc46ee1b0f541fba01adac0a6a3dd526924313;p=p5sagit%2Fp5-mst-13.2.git A fix for [perl #31692] : as PerlIO::scalar accesses directly the PV of the scalar it reads from, avoid to read it when it's an undefined PV. p4raw-id: //depot/perl@23340 --- diff --git a/ext/PerlIO/scalar/scalar.xs b/ext/PerlIO/scalar/scalar.xs index 193b99f..c116f07 100644 --- a/ext/PerlIO/scalar/scalar.xs +++ b/ext/PerlIO/scalar/scalar.xs @@ -39,7 +39,7 @@ PerlIOScalar_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, } SvUPGRADE(s->var, SVt_PV); code = PerlIOBase_pushed(aTHX_ f, mode, Nullsv, tab); - if ((PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE) + if (!SvOK(s->var) || (PerlIOBase(f)->flags) & PERLIO_F_TRUNCATE) SvCUR(s->var) = 0; if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND) s->posn = SvCUR(s->var); diff --git a/ext/PerlIO/t/scalar.t b/ext/PerlIO/t/scalar.t index 4021d43..818aab5 100644 --- a/ext/PerlIO/t/scalar.t +++ b/ext/PerlIO/t/scalar.t @@ -15,7 +15,7 @@ BEGIN { } $| = 1; -print "1..25\n"; +print "1..26\n"; my $fh; my $var = "ok 2\n"; @@ -143,3 +143,9 @@ print <$fh>; close $fh; print $ok ? "ok 25\n" : "not ok 25\n"; } + +my $data = "a non-empty PV"; +$data = undef; +open(MEM, '<', \$data) or die "Fail: $!\n"; +my $x = join '', ; +print $x eq '' ? "ok 26\n" : "not ok 26\n";