Skip to content

Commit

Permalink
fix for [perl #65582] anon globs segfaulting
Browse files Browse the repository at this point in the history
The following code has had differing behaviours:

    my $io_ref = *STDOUT{IO};
    my $glob = *$io_ref;

          defined($glob)    "$glob"
          --------------    -------
5.8.8       false           "" with uninit warning
5.10.0      true            (coredump)
this commit true            ""

$glob is essentially an anonymous typeglob (no NAME, EGV or GvSTASH).
It shouldn't register as undefined since it's clearly a valid GV with a
valid IO slot; Stringifying to "" seems to be the right thing, and not
warning seems right too, since its not undef.
  • Loading branch information
iabyn committed Jan 12, 2010
1 parent 0097b43 commit 1809c94
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
14 changes: 10 additions & 4 deletions sv.c
Expand Up @@ -2986,11 +2986,17 @@ Perl_sv_2pv_flags(pTHX_ register SV *const sv, STRLEN *const lp, const I32 flags
gv_efullname3(buffer, gv, "*");
SvFLAGS(gv) |= wasfake;

assert(SvPOK(buffer));
if (lp) {
*lp = SvCUR(buffer);
if (SvPOK(buffer)) {
if (lp) {
*lp = SvCUR(buffer);
}
return SvPVX(buffer);
}
else {
if (lp)
*lp = 0;
return (char *)"";
}
return SvPVX(buffer);
}

if (lp)
Expand Down
23 changes: 22 additions & 1 deletion t/op/gv.t
Expand Up @@ -12,7 +12,7 @@ BEGIN {
use warnings;

require './test.pl';
plan( tests => 178 );
plan( tests => 181 );

# type coersion on assignment
$foo = 'foo';
Expand Down Expand Up @@ -560,6 +560,27 @@ foreach my $type (qw(integer number string)) {
"with the correct error message");
}

# RT #60954 anonymous glob should be defined, and not coredump when
# stringified. The behaviours are:
#
# defined($glob) "$glob"
# 5.8.8 false "" with uninit warning
# 5.10.0 true (coredump)
# 5.12.0 true ""

{
my $io_ref = *STDOUT{IO};
my $glob = *$io_ref;
ok(defined $glob, "RT #60954 anon glob should be defined");

my $warn = '';
local $SIG{__WARN__} = sub { $warn = $_[0] };
use warnings;
my $str = "$glob";
is($warn, '', "RT #60954 anon glob stringification shouln't warn");
is($str, '', "RT #60954 anon glob stringification should be empty");
}

__END__
Perl
Rules
Expand Down

0 comments on commit 1809c94

Please sign in to comment.