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
Serious error with the handling of undef values #10561
Comments
From malch@malch.comThis is a bug report for perl from malch@malch.com, Operating System: 64-bit Windows 7. Perl Version: ActivePerl version 5.12.1.1201 64-bit: Flags: Code to reproduce this problem: #==================================================== @Big1 = (); #===================================================== Using ActivePerl version 5.12.1.1201 64-bit I get: C:\ZIP>c:\perl512\bin\perl.exe test.pl Using ActivePerl version 5.10.1.1007 64-bit I get: C:\ZIP>C:\perl510\bin\perl.exe test.pl Some other Perl programmers have taken the position that this I disagree and cite the following in support of my position 1. Perl Version 5.10.1.1007 and every other major Perl version 2. perlsyn clearly states: "A variable holds the undefined value ("undef") until it has been Thus "undef" should be treated as the empty string. And the Summary of my perl5 (revision 5 version 12 subversion 1) configuration: Platform: Characteristics of this binary (from libperl): --
|
From @ikegamiOn Fri, Aug 20, 2010 at 11:00 AM, Malcolm Hoar <perlbug-followup@perl.org>wrote:
Fixed in 5.12.1 by commit 656266f |
The RT System itself - Status changed from 'new' to 'open' |
From ben@morrow.me.ukQuoth Malcolm Hoar:
Subsequent discussion on clpmisc has reduced the testcase to my $x = 3; The bug was introduced by commit 9f621b (p4 rev 32969) which made Patch attached. Ben |
From ben@morrow.me.uk0001-Fix-my-x-3-x-length-undef.patchFrom 55f8b2ade4a0143d9a1b434fd83f187c81691352 Mon Sep 17 00:00:00 2001
From: Ben Morrow <ben@morrow.me.uk>
Date: Fri, 20 Aug 2010 18:35:58 +0100
Subject: [PATCH] Fix my $x = 3; $x = length(undef);.
Assignment of length() to a lexical is optimized by passing the
assigned-to variable as TARG, avoiding a pp_padsv and pp_sassign.
9f621b which changed length(undef) to return undef didn't take this into
account, and used SETs (which doesn't set TARG), so the code above left
$x == 3.
---
pp.c | 9 ++++++---
t/op/length.t | 17 ++++++++++++++++-
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/pp.c b/pp.c
index 0da8bba..fcb7ff2 100644
--- a/pp.c
+++ b/pp.c
@@ -3105,8 +3105,10 @@ PP(pp_length)
= sv_2pv_flags(sv, &len,
SV_UNDEF_RETURNS_NULL|SV_CONST_RETURN|SV_GMAGIC);
- if (!p)
- SETs(&PL_sv_undef);
+ if (!p) {
+ sv_setsv(TARG, &PL_sv_undef);
+ SETTARG;
+ }
else if (DO_UTF8(sv)) {
SETi(utf8_length((U8*)p, (U8*)p + len));
}
@@ -3119,7 +3121,8 @@ PP(pp_length)
else
SETi(sv_len(sv));
} else {
- SETs(&PL_sv_undef);
+ sv_setsv_nomg(TARG, &PL_sv_undef);
+ SETTARG;
}
RETURN;
}
diff --git a/t/op/length.t b/t/op/length.t
index c73d4c5..705b9d5 100644
--- a/t/op/length.t
+++ b/t/op/length.t
@@ -6,7 +6,7 @@ BEGIN {
@INC = '../lib';
}
-plan (tests => 30);
+plan (tests => 36);
print "not " unless length("") == 0;
print "ok 1\n";
@@ -193,6 +193,21 @@ my $uo = bless [], 'U';
is(length($uo), undef, "Length of overloaded reference");
+my $ul = 3;
+is(($ul = length(undef)), undef,
+ "Returned length of undef with result in TARG");
+is($ul, undef, "Assigned length of undef with result in TARG");
+
+$ul = 3;
+is(($ul = length($u)), undef,
+ "Returned length of tied undef with result in TARG");
+is($ul, undef, "Assigned length of tied undef with result in TARG");
+
+$ul = 3;
+is(($ul = length($uo)), undef,
+ "Returned length of overloaded undef with result in TARG");
+is($ul, undef, "Assigned length of overloaded undef with result in TARG");
+
# ok(!defined $uo); Turns you can't test this. FIXME for pp_defined?
is($warnings, 0, "There were no warnings");
--
1.7.1.1
|
From ben@morrow.me.ukQuoth ikegami@adaelis.com (Eric Brine):
No it's not. He was *using* 5.12.1. See my patch xthread. Ben |
@ikegami - Status changed from 'open' to 'resolved' |
@ikegami - Status changed from 'resolved' to 'open' |
From @ikegamiOn Fri Aug 20 11:01:00 2010, ben@morrow.me.uk wrote:
I couldn't reproduce with what I thought was blead, and the mixup |
From @csjewellI can also reproduce with my installations of Strawberry Perl, so it's |
From malch@malch.comCurtis Jewell via RT wrote:
Interesting. Thanks for letting me know! --
|
From @janduboisOn Fri, 20 Aug 2010, Ben Morrow wrote:
Thanks, applied as #d88e091f66. Given that it is a regression against 5.10.1 I'll nominate this as Cheers, |
From @obra
It's not, and I +1 it :)
-- |
From @TuxOn Fri, 20 Aug 2010 19:46:39 -0400, Jesse Vincent <jesse@fsck.com>
but not yet in cherrymaint. only jdb and me have touched it for now -- |
From @janduboisOn Sat, 21 Aug 2010, H.Merijn Brand wrote:
A vote on the mailing list is good enough for me; I've now applied the Just for record keeping purposes it would be good to see Jesse's +1 on Cheers, |
From @obraOn Sun, Aug 22, 2010 at 11:44:48AM -0700, Jan Dubois wrote:
Done.
-- |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#77336 (status was 'resolved')
Searchable as RT77336$
The text was updated successfully, but these errors were encountered: