-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Use of uninitialized value" in warn() with constant folding and overloaded numbers #16349
Comments
From trizen@protonmail.comHi, There seems to be a minor issue: when warn() is used in an overloaded built-in function which is subject to constant folding and the argument is an overloaded number (with overload::constant), it displays "Use of uninitialized value in warn", although no uninitialized value is passed to warn(). Example: use strict; package Foo; use overload log => sub { sub import { sub new { package main; BEGIN { Foo->import } The output is: Use of uninitialized value in warn at bug.pl line 7. This warning happens at compile-time, as can be illustrated with `perl -c`: $ perl -c x.pl here x.pl syntax OK The issue was reproduced with perl-5.18.4, perl-5.26.1 and perl-5.27.7. Output of `perlbug -d`: Flags: Site configuration information for perl 5.26.1: Configured by builduser at Sat Sep 23 16:41:42 CEST 2017. Summary of my perl5 (revision 5 version 26 subversion 1) configuration: Platform: @INC for perl 5.26.1: Environment for perl 5.26.1: |
From @tonycozOn Thu, 04 Jan 2018 23:09:07 -0800, trizen@protonmail.com wrote:
Try the attached. Thanks, |
From @tonycoz0001-perl-132683-don-t-try-to-convert-PL_sv_placeholder-i.patchFrom 536b91a5640beba18185316f709279a8d2e588be Mon Sep 17 00:00:00 2001
From: Tony Cook <tony@develop-help.com>
Date: Wed, 21 Feb 2018 16:24:08 +1100
Subject: (perl #132683) don't try to convert PL_sv_placeholder into a CV
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.
---
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 647f53307d..07ca5c7b1d 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.11.0
|
The RT System itself - Status changed from 'new' to 'open' |
From @tonycozOn Tue, 20 Feb 2018 21:24:56 -0800, tonyc wrote:
Applied as 2460a49. Tony |
@tonycoz - Status changed from 'open' to 'pending release' |
From @khwilliamsonThank you for filing this report. You have helped make Perl better. With the release today of Perl 5.30.0, this and 160 other issues have been Perl 5.30.0 may be downloaded via: If you find that the problem persists, feel free to reopen this ticket. |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#132683 (status was 'resolved')
Searchable as RT132683$
The text was updated successfully, but these errors were encountered: