From: Father Chrysostomos Date: Sat, 9 Nov 2013 21:44:27 +0000 (-0800) Subject: Stop open fh, ">>", \$undef from warning X-Git-Tag: upstream/5.20.0~1311 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7f7e7b583c6e4a7c1a86bc3badc65d1c15fe08d4;p=platform%2Fupstream%2Fperl.git Stop open fh, ">>", \$undef from warning $ ./perl t/TEST ../cpan/Test-Simple/t/subtest/bail_out.t t/../cpan/Test-Simple/t/subtest/bail_out ... Use of uninitialized value in open at /Users/sprout/Perl/perl.git-copy/cpan/Test-Simple/../../lib/Test/Builder.pm line 1895. ok All tests successful. u=0.01 s=0.00 cu=0.09 cs=0.01 scripts=1 tests=2 Notice the uninitialized value. $ ./perl -Ilib -Mwarnings=uninitialized -e 'open $fh, ">>", \$x' Use of uninitialized value $x in open at -e line 1. $ perl5.18.1 -Mwarnings=uninitialized -e 'open $fh, ">>", \$x' I caused that in v5.19.5-44-g5a2bc23: $ ../perl.git/Porting/bisect.pl --start=045071eede --end=blead -e 'use warnings FATAL=>"uninitialized"; open $fh, ">>", \$x' ... 5a2bc23bfe5dc60ff957cb44ffaa57668d56d238 is the first bad commit commit 5a2bc23bfe5dc60ff957cb44ffaa57668d56d238 Author: Father Chrysostomos Date: Fri Oct 25 06:15:30 2013 -0700 Better fix for #119529 --- diff --git a/ext/PerlIO-scalar/scalar.xs b/ext/PerlIO-scalar/scalar.xs index 552345d..a104887 100644 --- a/ext/PerlIO-scalar/scalar.xs +++ b/ext/PerlIO-scalar/scalar.xs @@ -66,7 +66,7 @@ PerlIOScalar_pushed(pTHX_ PerlIO * f, const char *mode, SV * arg, return -1; } if ((PerlIOBase(f)->flags) & PERLIO_F_APPEND) - s->posn = sv_len(s->var); + s->posn = SvOK(s->var) ? sv_len(s->var) : 0; else s->posn = 0; SvSETMAGIC(s->var); diff --git a/ext/PerlIO-scalar/t/scalar.t b/ext/PerlIO-scalar/t/scalar.t index a1d2b53..9bc1abe 100644 --- a/ext/PerlIO-scalar/t/scalar.t +++ b/ext/PerlIO-scalar/t/scalar.t @@ -16,7 +16,7 @@ use Fcntl qw(SEEK_SET SEEK_CUR SEEK_END); # Not 0, 1, 2 everywhere. $| = 1; -use Test::More tests => 113; +use Test::More tests => 114; my $fh; my $var = "aaa\n"; @@ -109,6 +109,11 @@ is(<$fh>, "shazam", "reading from magic scalars"); print $fh "foo"; close $fh; is($warn, 0, "no warnings when writing to an undefined scalar"); + undef $scalar; + open $fh, '>>', \$scalar; + print $fh "oof"; + close $fh; + is($warn, 0, "no warnings when appending to an undefined scalar"); } {