Fix a spurious warning about uninitialized value in warn

This commit is contained in:
Petr Písař 2018-09-05 16:40:58 +02:00
parent e7c58147e0
commit 312df55ba1
2 changed files with 86 additions and 0 deletions

View File

@ -0,0 +1,79 @@
From 2460a4968c375f226973ba7e7e5fe6cf5a997ddb Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 21 Feb 2018 16:24:08 +1100
Subject: [PATCH] (perl #132683) don't try to convert PL_sv_placeholder into a
CV
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Constant folding sets PL_warnhook to PERL_WARNHOOK_FATAL, which is
&PL_sv_placeholder, an undef SV.
If warn() is called while constant folding, invoke_exception_hook()
attempts to use the value of a non-NULL PL_warnhook as a CV, which
caused an undefined value warning.
invoke_exception_hook() now treats a PL_warnhook of PERL_WARNHOOK_FATAL
the same as NULL, falling back to the normal warning handling which
throws an exception to abort constant folding.
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
t/lib/warnings/util | 29 +++++++++++++++++++++++++++++
util.c | 2 +-
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/t/lib/warnings/util b/t/lib/warnings/util
index e82d6a6617..92be6efa73 100644
--- a/t/lib/warnings/util
+++ b/t/lib/warnings/util
@@ -106,3 +106,32 @@ no warnings 'portable' ;
$a = oct "0047777777777" ;
EXPECT
Octal number > 037777777777 non-portable at - line 5.
+########
+# util.c
+# NAME 132683: Use of uninitialized value" in warn() with constant folding and overloaded numbers
+use strict;
+use warnings;
+
+package Foo;
+
+use overload log => sub {
+ warn "here\n"; # Use of uninitialized value in warn
+ CORE::log($_[0]->{value});
+};
+
+sub import {
+ overload::constant
+ integer => sub { __PACKAGE__->new($_[0]) };
+}
+
+sub new {
+ my ($class, $value) = @_;
+ bless {value => $value}, $class;
+}
+
+package main;
+
+BEGIN { Foo->import }
+my $x = log(2);
+EXPECT
+here
diff --git a/util.c b/util.c
index 37a71a1a81..ff88a54bf6 100644
--- a/util.c
+++ b/util.c
@@ -1534,7 +1534,7 @@ S_invoke_exception_hook(pTHX_ SV *ex, bool warn)
/* sv_2cv might call Perl_croak() or Perl_warner() */
SV * const oldhook = *hook;
- if (!oldhook)
+ if (!oldhook || oldhook == PERL_WARNHOOK_FATAL)
return FALSE;
ENTER;
--
2.14.4

View File

@ -202,6 +202,10 @@ Patch29: perl-5.29.1-Update-Time-Piece-to-CPAN-version-1.33.patch
# RT#133441, in upstream after 5.29.2
Patch30: perl-5.29.2-multiconcat-mutator-not-seen-in-lex.patch
# Fix a spurious warning about uninitialized value in warn, RT#132683,
# in upstream after 5.29.2
Patch31: perl-5.29.2-perl-132683-don-t-try-to-convert-PL_sv_placeholder-i.patch
# Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048
Patch200: perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@ -2783,6 +2787,7 @@ Perl extension for Version Objects
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%patch200 -p1
%patch201 -p1
@ -2820,6 +2825,7 @@ perl -x patchlevel.h \
'Fedora Patch28: Fix matching an ASCII digit followed by a non-ASCII digit using a script run' \
'Fedora Patch29: Fix Time::Piece to handle objects in overloaded methods correctly' \
'Fedora Patch30: Fix an assignment to a lexical variable in multiconcatenation expressions (RT#133441)' \
'Fedora Patch31: Fix a spurious warning about uninitialized value in warn (RT#132683)' \
'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \
'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
%{nil}
@ -5116,6 +5122,7 @@ popd
- Fix Time::Piece to handle objects in overloaded methods correctly
- Fix an assignment to a lexical variable in multiconcatenation expressions
(RT#133441)
- Fix a spurious warning about uninitialized value in warn (RT#132683)
* Wed Aug 01 2018 Petr Pisar <ppisar@redhat.com> - 4:5.28.0-420
- Fix a file descriptor leak in in-place edits (RT#133314)