Branch: refs/heads/yves/fix_19472_warns_on_undef_scalar_ref_open
  Home:   https://github.com/Perl/perl5
  Commit: 371ddaca984535e73b2d88984653f9f6ec6f569b
      
https://github.com/Perl/perl5/commit/371ddaca984535e73b2d88984653f9f6ec6f569b
  Author: Yves Orton <[email protected]>
  Date:   2022-03-04 (Fri, 04 Mar 2022)

  Changed paths:
    M doio.c
    M t/io/open.t

  Log Message:
  -----------
  Fix GH Issue #19472: read warnings from open($fh,">",\(my $x))

We produce all kinds of warnings if someone opens a scalar reference
that is undef. Prior to this we handled write operations ok, at
least in blead, but read operations would produce a plethora of
warnings. To me this analagous to treating an undef var as hash
and trying to read from it, we autovivify the undef var to be
a hash. So in this case we should just "autovivify" the referenced
scalar to be an empty string.

Eg before this patch:

./perl -Ilib -wle'open my $fh,"+>", \(my $v); my @x=<$fh>; print 0+@x'
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
Use of uninitialized value $fh in <HANDLE> at -e line 1.
0

After it:
./perl -Ilib -wle'open my $fh,"+>", \(my $v); my @x=<$fh>; print 0+@x'
0


Reply via email to