develooper Front page | perl.perl5.porters | Postings from November 2005

Re: [perl #37731] junk and uninit'ed values in tied scalars

Thread Previous | Thread Next
From:
Robin Houston
Date:
November 28, 2005 05:10
Subject:
Re: [perl #37731] junk and uninit'ed values in tied scalars
Message ID:
20051128130817.GC14694@rpc142.cs.man.ac.uk
The below seems okay against 5.8.x.

Robin

--- pp_hot.c.orig	2005-11-28 13:07:29.000000000 +0000
+++ pp_hot.c	2005-11-28 13:07:38.000000000 +0000
@@ -151,19 +151,22 @@
     dPOPTOPssrl;
     bool lbyte;
     STRLEN rlen;
-    const char *rpv = SvPV_const(right, rlen);	/* mg_get(right) happens here */
-    const bool rbyte = !DO_UTF8(right);
+    const char *lpv = 0, *rpv;
+    bool rbyte;
     bool rcopied = FALSE;
+    STRLEN llen;
 
     if (TARG == right && right != left) {
+	/* mg_get(right) may happen here ... */
+	rpv = SvPV_const(right, rlen);
+	rbyte = !DO_UTF8(right);
 	right = sv_2mortal(newSVpvn(rpv, rlen));
 	rpv = SvPV_const(right, rlen);	/* no point setting UTF-8 here */
 	rcopied = TRUE;
     }
 
     if (TARG != left) {
-        STRLEN llen;
-        const char* const lpv = SvPV_const(left, llen);	/* mg_get(left) may happen here */
+        lpv = SvPV_const(left, llen);	/* mg_get(left) may happen here */
 	lbyte = !DO_UTF8(left);
 	sv_setpvn(TARG, lpv, llen);
 	if (!lbyte)
@@ -172,19 +175,28 @@
 	    SvUTF8_off(TARG);
     }
     else { /* TARG == left */
-        STRLEN llen;
 	if (SvGMAGICAL(left))
 	    mg_get(left);		/* or mg_get(left) may happen here */
-	if (!SvOK(TARG))
+	if (!SvOK(TARG)) {
+	    if (left == right && ckWARN(WARN_UNINITIALIZED))
+		report_uninit();
 	    sv_setpvn(left, "", 0);
+        }
 	(void)SvPV_nomg_const(left, llen);    /* Needed to set UTF8 flag */
 	lbyte = !DO_UTF8(left);
 	if (IN_BYTES)
 	    SvUTF8_off(TARG);
     }
 
+    /* or mg_get(right) may happen here */
+    if (!rcopied) {
+       rpv = SvPV_const(right, rlen);
+       rbyte = !DO_UTF8(right);
+    }
+
 #if defined(PERL_Y2KWARN)
-    if ((SvIOK(right) || SvNOK(right)) && ckWARN(WARN_Y2K) && SvOK(TARG)) {
+    if ((SvIOK(right) || SvNOK(right)) && lpv
+    && ckWARN(WARN_Y2K) && SvOK(TARG)) {
 	if (llen >= 2 && lpv[llen - 2] == '1' && lpv[llen - 1] == '9'
 	    && (llen == 2 || !isDIGIT(lpv[llen - 3])))
 	{
--- t/op/tie.t.orig	2005-11-28 12:56:04.000000000 +0000
+++ t/op/tie.t	2005-11-28 12:57:36.000000000 +0000
@@ -547,3 +547,10 @@
 print $h,"\n";
 EXPECT
 3.3
+########
+sub TIESCALAR { bless {} }
+sub FETCH { shift()->{i} ++ }
+tie $h, "main";
+print $h.$h;
+EXPECT
+01

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