Blame SOURCES/perl-5.25.2-uninit-warning-from-h-const-coredumped.patch

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