New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
string corruption with lvalue sub #6838
Comments
From mconst@csua.berkeley.eduCreated by mconst@csua.berkeley.eduUnder perl v5.8.1 on my i386 Debian Linux system, this script: $foo = "a"; produces the output "X". I would have expected it to output "XXX", I get the same behaviour with perl v5.6.1 on an i386 FreeBSD system. If you run the program under a debugging perl, you can actually see (./bugtest:2) substr STACK 0: MAIN (./bugtest:2) leavesublv STACK 0: MAIN Am I doing something wrong? Perl Info
|
From @ysthOn Mon, Oct 13, 2003 at 05:28:49PM -0000, "mconst@csua.berkeley.edu (via RT)" <perlbug-followup@perl.org> wrote:
Looks like substr is expecting to always or never return an lvalue. This is a start: Inline Patch--- perl/pp.c.orig 2003-10-14 23:55:45.673918400 -0700
+++ perl/pp.c 2003-10-14 23:58:14.748276800 -0700
@@ -3079,6 +3079,8 @@
SvREFCNT_dec(LvTARG(TARG));
LvTARG(TARG) = SvREFCNT_inc(sv);
}
+ }
+ if (SvTYPE(TARG) == SVt_PVLV) {
LvTARGOFF(TARG) = upos;
LvTARGLEN(TARG) = urem;
}
but it needs more. The non-lvalue but a PVLV case needs to handle Can someone more familiar with TARG reuse take a look at this? |
From @ysthI repeat my plea for someone with knowlege about using TARG to look at On Wed, Oct 15, 2003 at 12:18:16AM -0700, Yitzchak Scott-Thoennes <sthoenna@efn.org> wrote:
|
From @iabynOn Wed, Oct 15, 2003 at 12:18:16AM -0700, Yitzchak Scott-Thoennes wrote:
I'm the person who added the TARG REFCNT > 1 test, so I claim to know a Dave. -- Inline Patch--- ../22168.ORIG/pp.c Sat Jan 17 18:31:44 2004
+++ pp.c Sat Jan 24 00:49:58 2004
@@ -3027,6 +3027,19 @@ PP(pp_substr)
if (utf8_curlen)
sv_pos_u2b(sv, &pos, &rem);
tmps += pos;
+ /* we either return a PV or an LV. If the TARG hasn't been used
+ * before, or is of that type, reuse it; otherwise use a mortal
+ * instead. Note that LVs can have an extended lifetime, so also
+ * dont reuse if refcount > 1 (bug #20933) */
+ if (SvTYPE(TARG) > SVt_NULL) {
+ if ( (SvTYPE(TARG) == SVt_PVLV)
+ ? (!lvalue || SvREFCNT(TARG) > 1)
+ : lvalue)
+ {
+ TARG = sv_newmortal();
+ }
+ }
+
sv_setpvn(TARG, tmps, rem);
#ifdef USE_LOCALE_COLLATE
sv_unmagic(TARG, PERL_MAGIC_collxfrm);
@@ -3063,8 +3076,6 @@ PP(pp_substr)
sv_setpvn(sv,"",0); /* avoid lexical reincarnation */
}
- if (SvREFCNT(TARG) > 1) /* don't share the TARG (#20933) */
- TARG = sv_newmortal();
if (SvTYPE(TARG) < SVt_PVLV) {
sv_upgrade(TARG, SVt_PVLV);
sv_magic(TARG, Nullsv, PERL_MAGIC_substr, Nullch, 0); |
From @ysthOn Sat, Jan 24, 2004 at 01:05:20AM +0000, Dave Mitchell <davem@fdisolutions.com> wrote:
Looks ok. Do you want to come up with tests for this or shall I? |
From @iabynOn Sun, Jan 25, 2004 at 02:37:49AM -0800, Yitzchak Scott-Thoennes wrote:
I'm happy for you to do so :-) -- |
From @nwc10On Sun, Jan 25, 2004 at 12:10:52PM +0000, Dave Mitchell wrote:
I think that in general having tests written by someone other than the patch Nicholas Clark |
From @iabynOn Sat, Jan 24, 2004 at 01:05:20AM +0000, Dave Mitchell wrote:
I've now belatedly applied my patch to bleedperl, along with some tests. Dave. Change 22599 by davem@davem-percy on 2004/03/27 01:54:09 [perl #24200] string corruption with lvalue sub Affected files ... ... //depot/perl/pp.c#411 edit Differences ... ==== //depot/perl/pp.c#411 (text) ==== @@ -3038,6 +3038,19 @@ - if (SvREFCNT(TARG) > 1) /* don't share the TARG (#20933) */ ==== //depot/perl/t/op/substr.t#28 (xtext) ==== @@ -1,6 +1,6 @@ -print "1..186\n"; #P = start of string Q = start of substr R = end of substr S = end of string @@ -629,3 +629,14 @@ |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#24200 (status was 'resolved')
Searchable as RT24200$
The text was updated successfully, but these errors were encountered: