diff options
author | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2004-09-30 15:12:29 +0000 |
---|---|---|
committer | Rafael Garcia-Suarez <rgarciasuarez@gmail.com> | 2004-09-30 15:12:29 +0000 |
commit | 47cc46ee1b0f541fba01adac0a6a3dd526924313 (patch) | |
tree | ab23eb3088fbba3914a222ca7c9e93cd7b6da55b /ext | |
parent | 3afc138ae8d937f9bbca45350859ec2c8429f730 (diff) | |
download | perl-47cc46ee1b0f541fba01adac0a6a3dd526924313.tar.gz |
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
Diffstat (limited to 'ext')
-rw-r--r-- | ext/PerlIO/scalar/scalar.xs | 2 | ||||
-rw-r--r-- | ext/PerlIO/t/scalar.t | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/ext/PerlIO/scalar/scalar.xs b/ext/PerlIO/scalar/scalar.xs index 193b99f3c8..c116f07f17 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 4021d431a2..818aab575f 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 '', <MEM>; +print $x eq '' ? "ok 26\n" : "not ok 26\n"; |