Skip to content

Commit

Permalink
uninit warning from $h{\const} coredumped
Browse files Browse the repository at this point in the history
The code that printed the the name and subscript of a hash element
in an "uninitialized variable" warning assumed that a constant
hash subscript would be SvPOK. Something like \1 is a constant,
but is ROK, not POK. SEGVs ensured.
  • Loading branch information
iabyn committed Jun 21, 2016
1 parent e6da2a9 commit 55b6481
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
5 changes: 4 additions & 1 deletion sv.c
Expand Up @@ -15683,9 +15683,12 @@ Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ,

if (subscript_type == FUV_SUBSCRIPT_HASH) {
SV * const sv = newSV(0);
STRLEN len;
const char * const pv = SvPV_nomg_const((SV*)keyname, len);

*SvPVX(name) = '$';
Perl_sv_catpvf(aTHX_ name, "{%s}",
pv_pretty(sv, SvPVX_const(keyname), SvCUR(keyname), 32, NULL, NULL,
pv_pretty(sv, pv, len, 32, NULL, NULL,
PERL_PV_PRETTY_DUMP | PERL_PV_ESCAPE_UNI_DETECT ));
SvREFCNT_dec_NN(sv);
}
Expand Down
19 changes: 18 additions & 1 deletion t/op/hashwarn.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
}

require './test.pl';
plan( tests => 16 );
plan( tests => 18 );

use strict;
use warnings;
Expand Down Expand Up @@ -71,3 +71,20 @@ my $fail_not_hr = 'Not a HASH reference at ';
cmp_ok(scalar(@warnings),'==',0,'pseudo-hash 2 count');
cmp_ok(substr($@,0,length($fail_not_hr)),'eq',$fail_not_hr,'pseudo-hash 2 msg');
}

# RT #128189
# this used to coredump

{
@warnings = ();
my %h;

no warnings;
use warnings qw(uninitialized);

my $x = "$h{\1}";
is(scalar @warnings, 1, "RT #128189 - 1 warning");
like("@warnings",
qr/Use of uninitialized value \$h\{"SCALAR\(0x[\da-f]+\)"\}/,
"RT #128189 correct warning");
}

0 comments on commit 55b6481

Please sign in to comment.