Re: [perl #19582] [PATCH bleedperl] bad overload copy constructor segfaults
authorRick Delaney <rick@consumercontact.com>
Wed, 1 Jan 2003 22:54:59 +0000 (17:54 -0500)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 18 Sep 2003 19:15:07 +0000 (19:15 +0000)
Message-ID: <20030101225459.A2320@cs839290-a.mtth.phub.net.cable.rogers.com>

(Pity the first patch fell through the cracks back then.
 Not that forbidding non-object copy constructors is the right
 thing to do but the bug could use fixing.)

p4raw-id: //depot/perl@21276

lib/overload.t
pp.h

index 0aba79f..3490b5b 100644 (file)
@@ -1087,5 +1087,21 @@ print $@ =~ /zap/ ? "ok 227\n" : "not ok 227\n";
 
 print overload::StrVal(qr/a/) =~ /^Regexp=SCALAR\(0x[0-9a-f]+\)$/ ? "ok 228\n" : "not ok 228\n";
 
+{
+   package t229;
+   use overload '='  => sub { 42 },
+                '++' => sub { my $x = ${$_[0]}; $_[0] };
+   sub new { my $x = 42; bless \$x }
+
+   my $warn;
+   {  
+     local $SIG{__WARN__} = sub { $warn++ };
+      my $x = t229->new;
+      my $y = $x;
+      eval { $y++ };
+   }
+   print $warn ? "not ok 229\n" : "ok 229\n";
+}
+
 # Last test is:
-sub last {228}
+sub last {229}
diff --git a/pp.h b/pp.h
index 8986db9..3893c10 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -385,8 +385,8 @@ See C<PUSHu>.
    changed SV* ref to SV* tmpRef */
 #define RvDEEPCP(rv) STMT_START { SV* tmpRef=SvRV(rv);      \
   if (SvREFCNT(tmpRef)>1) {                 \
+    SvRV(rv)=AMG_CALLun(rv,copy);      \
     SvREFCNT_dec(tmpRef);                   \
-    SvRV(rv)=AMG_CALLun(rv,copy);        \
   } } STMT_END
 
 /*