From: Nicholas Clark <nick@ccl4.org>
Date: Mon, 27 Jun 2005 20:52:27 +0000 (+0000)
Subject: Fix sv_dec of undefined PVs to (a) not downgrade to NV
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ef088171612d4ee5ba22258b0578312b3d9a1f01;p=p5sagit%2Fp5-mst-13.2.git

Fix sv_dec of undefined PVs to (a) not downgrade to NV
(b) give -1, rather than +1

p4raw-id: //depot/perl@24998
---

diff --git a/sv.c b/sv.c
index 26e780e..c2d8572 100644
--- a/sv.c
+++ b/sv.c
@@ -7075,10 +7075,10 @@ Perl_sv_dec(pTHX_ register SV *sv)
 	return;
     }
     if (!(flags & SVp_POK)) {
-	if ((flags & SVTYPEMASK) < SVt_PVNV)
-	    sv_upgrade(sv, SVt_NV);
-	SvNV_set(sv, 1.0);
-	(void)SvNOK_only(sv);
+	if ((flags & SVTYPEMASK) < SVt_PVIV)
+	    sv_upgrade(sv, ((flags & SVTYPEMASK) > SVt_IV) ? SVt_PVIV : SVt_IV);
+	SvIV_set(sv, -1);
+	(void)SvIOK_only(sv);
 	return;
     }
 #ifdef PERL_PRESERVE_IVUV
diff --git a/t/op/inc.t b/t/op/inc.t
index 56d27d2..156ca92 100755
--- a/t/op/inc.t
+++ b/t/op/inc.t
@@ -2,7 +2,7 @@
 
 # use strict;
 
-print "1..26\n";
+print "1..30\n";
 
 my $test = 1;
 
@@ -157,3 +157,22 @@ foreach (keys %postdec) {
 }
 
 check_same (\%orig, \%postdec);
+
+{
+    no warnings 'uninitialized';
+    my $x, $y;
+    eval {
+	$y ="$x\n";
+	++$x;
+    };
+    ok($x == 1, $x);
+    ok($@ eq '', $@);
+
+    my $p, $q;
+    eval {
+	$q ="$p\n";
+	--$p;
+    };
+    ok($p == -1, $p);
+    ok($@ eq '', $@);
+}