From: John Q. Linux Date: Sat, 11 Jan 1997 03:47:16 +0000 (-0800) Subject: Forbid ++ and -- on readonly values X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=74c80e585086695d5428ab316ca82fd6931aeabd;p=p5sagit%2Fp5-mst-13.2.git Forbid ++ and -- on readonly values Subject: You can ++ and -- readonly integer scalars? (patch included) I managed to find an illustration of the bug in a perl one-liner: perl -e '*a = \100; $a++; print "$a\n"' 101 Perhaps that's been fixed in one of the beta releases which I'm not running; or perhaps I'm the only one who finds that slightly incorrect. If so, ignore the rest of this message. You can modify readonly scalars using any of the pre/post increment/decrement operators. Apparently, the only readonly checking is done for cases like '100++'. I managed to find the relevant code and add some SvREADONLY checks. It now dies on the inc/dec of readonly scalars with the appropriate nasty message. I just thought I'd share my patch. Ashley Winters p5p-msgid: --- diff --git a/pp.c b/pp.c index 48e3321..f4cdc2d 100644 --- a/pp.c +++ b/pp.c @@ -575,6 +575,8 @@ PP(pp_undef) PP(pp_predec) { dSP; + if (SvREADONLY(TOPs)) + croak(no_modify); if (SvIOK(TOPs)) { if (SvIVX(TOPs) == IV_MIN) { sv_setnv(TOPs, (double)SvIVX(TOPs) - 1.0); @@ -593,6 +595,8 @@ PP(pp_predec) PP(pp_postinc) { dSP; dTARGET; + if (SvREADONLY(TOPs)) + croak(no_modify); sv_setsv(TARG, TOPs); if (SvIOK(TOPs)) { if (SvIVX(TOPs) == IV_MAX) { @@ -615,6 +619,8 @@ PP(pp_postinc) PP(pp_postdec) { dSP; dTARGET; + if(SvREADONLY(TOPs)) + croak(no_modify); sv_setsv(TARG, TOPs); if (SvIOK(TOPs)) { if (SvIVX(TOPs) == IV_MIN) { diff --git a/pp_hot.c b/pp_hot.c index 150afe2..f1ee8f2 100644 --- a/pp_hot.c +++ b/pp_hot.c @@ -251,6 +251,8 @@ PP(pp_eq) PP(pp_preinc) { dSP; + if (SvREADONLY(TOPs)) + croak(no_modify); if (SvIOK(TOPs)) { if (SvIVX(TOPs) == IV_MAX) { sv_setnv(TOPs, (double)(SvIVX(TOPs)) + 1.0 );