b8876f
From 55b6481ff87f84626ba01275708297a42a6537b1 Mon Sep 17 00:00:00 2001
b8876f
From: David Mitchell <davem@iabyn.com>
b8876f
Date: Tue, 21 Jun 2016 15:23:20 +0100
b8876f
Subject: [PATCH] uninit warning from $h{\const} coredumped
b8876f
MIME-Version: 1.0
b8876f
Content-Type: text/plain; charset=UTF-8
b8876f
Content-Transfer-Encoding: 8bit
b8876f
b8876f
The code that printed the the name and subscript of a hash element
b8876f
in an "uninitialized variable" warning assumed that a constant
b8876f
hash subscript would be SvPOK. Something like \1 is a constant,
b8876f
but is ROK, not POK. SEGVs ensured.
b8876f
b8876f
Signed-off-by: Petr Písař <ppisar@redhat.com>
b8876f
---
b8876f
 sv.c            |  5 ++++-
b8876f
 t/op/hashwarn.t | 19 ++++++++++++++++++-
b8876f
 2 files changed, 22 insertions(+), 2 deletions(-)
b8876f
b8876f
diff --git a/sv.c b/sv.c
b8876f
index 535ee8d..b0fdd15 100644
b8876f
--- a/sv.c
b8876f
+++ b/sv.c
b8876f
@@ -15683,9 +15683,12 @@ Perl_varname(pTHX_ const GV *const gv, const char gvtype, PADOFFSET targ,
b8876f
 
b8876f
     if (subscript_type == FUV_SUBSCRIPT_HASH) {
b8876f
 	SV * const sv = newSV(0);
b8876f
+        STRLEN len;
b8876f
+        const char * const pv = SvPV_nomg_const((SV*)keyname, len);
b8876f
+
b8876f
 	*SvPVX(name) = '$';
b8876f
 	Perl_sv_catpvf(aTHX_ name, "{%s}",
b8876f
-	    pv_pretty(sv, SvPVX_const(keyname), SvCUR(keyname), 32, NULL, NULL,
b8876f
+	    pv_pretty(sv, pv, len, 32, NULL, NULL,
b8876f
 		    PERL_PV_PRETTY_DUMP | PERL_PV_ESCAPE_UNI_DETECT ));
b8876f
 	SvREFCNT_dec_NN(sv);
b8876f
     }
b8876f
diff --git a/t/op/hashwarn.t b/t/op/hashwarn.t
b8876f
index a6a1de9..6d72244 100644
b8876f
--- a/t/op/hashwarn.t
b8876f
+++ b/t/op/hashwarn.t
b8876f
@@ -6,7 +6,7 @@ BEGIN {
b8876f
 }
b8876f
 
b8876f
 require './test.pl';
b8876f
-plan( tests => 16 );
b8876f
+plan( tests => 18 );
b8876f
 
b8876f
 use strict;
b8876f
 use warnings;
b8876f
@@ -71,3 +71,20 @@ my $fail_not_hr   = 'Not a HASH reference at ';
b8876f
     cmp_ok(scalar(@warnings),'==',0,'pseudo-hash 2 count');
b8876f
     cmp_ok(substr($@,0,length($fail_not_hr)),'eq',$fail_not_hr,'pseudo-hash 2 msg');
b8876f
 }
b8876f
+
b8876f
+# RT #128189
b8876f
+# this used to coredump
b8876f
+
b8876f
+{
b8876f
+    @warnings = ();
b8876f
+    my %h;
b8876f
+
b8876f
+    no warnings;
b8876f
+    use warnings qw(uninitialized);
b8876f
+
b8876f
+    my $x = "$h{\1}";
b8876f
+    is(scalar @warnings, 1, "RT #128189 - 1 warning");
b8876f
+    like("@warnings",
b8876f
+        qr/Use of uninitialized value \$h\{"SCALAR\(0x[\da-f]+\)"\}/,
b8876f
+        "RT #128189 correct warning");
b8876f
+}
b8876f
-- 
b8876f
2.5.5
b8876f