Stop open fh, ">>", \$undef from warning
authorFather Chrysostomos <sprout@cpan.org>
Sat, 9 Nov 2013 21:44:27 +0000 (13:44 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 10 Nov 2013 01:02:17 +0000 (17:02 -0800)
$ ./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 <sprout@cpan.org>
Date:   Fri Oct 25 06:15:30 2013 -0700

    Better fix for #119529

ext/PerlIO-scalar/scalar.xs
ext/PerlIO-scalar/t/scalar.t

index 552345d..a104887 100644 (file)
@@ -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);
index a1d2b53..9bc1abe 100644 (file)
@@ -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");
 }
 
 {