develooper Front page | perl.perl5.porters | Postings from May 2004

Re: [perl #29127] Empty tied hash delete in scalar context seems to pick up random trash from the stack

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
May 3, 2004 12:14
Subject:
Re: [perl #29127] Empty tied hash delete in scalar context seems to pick up random trash from the stack
Message ID:
20040503191845.GG1895@iabyn.com
On Wed, Apr 28, 2004 at 01:54:12PM +0000, Ton Hospel wrote:
> The tie is a red herring. It happens like this too:
> 
> #! /usr/bin/perl -wl
> print "foo=" . delete @cache{()};
> print scalar delete @cache{()} for "bar";

fixed in belldperl by the change below.

Dave.

-- 
You live and learn (although usually you just live).

Change 22775 by davem@davem-percy on 2004/05/03 18:52:39

	[perl #29127] scalar delete of empty slice returned garbage

Affected files ...

... //depot/perl/pp.c#415 edit
... //depot/perl/t/op/delete.t#9 edit

Differences ...

==== //depot/perl/pp.c#415 (text) ====

@@ -3795,7 +3795,10 @@
 	    SP = ORIGMARK;
 	else if (gimme == G_SCALAR) {
 	    MARK = ORIGMARK;
-	    *++MARK = *SP;
+	    if (SP > MARK)
+		*++MARK = *SP;
+	    else
+		*++MARK = &PL_sv_undef;
 	    SP = MARK;
 	}
     }

==== //depot/perl/t/op/delete.t#9 (xtext) ====

@@ -1,6 +1,6 @@
 #!./perl
 
-print "1..36\n";
+print "1..37\n";
 
 # delete() on hash elements
 
@@ -121,3 +121,11 @@
     print "not " unless $a == $b && $b == $c;
     print "ok 36\n";
 }
+
+{
+    # [perl #29127] scalar delete of empty slice returned garbage
+    my %h;
+    my ($x,$y) = (1, scalar delete @h{()});
+    print "not " if defined $y;
+    print "ok 37\n";
+}

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About