Closed p5pRT closed 16 years ago
#======== test.pl ========= use strict; my @items = (1\, 2\, 3); my $k = -1; foreach my $item (@items) { $k++; $items[$k+1]=~m/xxx/; } exit; #======== test.pl =========
perl test.pl Out of memory! ^C
Yeah\, not great code but the failure mode is horrible! This was not a problem on the overwhelming majority of prior releases.
This with ActivePerl Build 630 under Win 2000 SP2
Oddly enough\, I have no problem in Linux 5.6.1 with this code\, but bleadperl does. Just chews memory.
I think the problem is $foo[23] =~ /failed match/ is causing that element to spring into existence\, which is used to not do.
$ perl -le '$foo[23] =~ /moo/; print $#foo' -1 $ bleadperl -wle '$foo[23] =~ /moo/; print $#foo' 23
Thus the array is extended inside the foreach loop\, which causes an infinite loop.
--
Michael G. Schwern \schwern@​pobox\.com http://www.pobox.com/~schwern/ Perl Quality Assurance \perl\-qa@​perl\.org Kwalitee Is Job One viscosity dawns creamy\, juicy\, filling paste open wide fucker -- imploded
Malcolm Hoar \malch@​malch\.com wrote: :perl test.pl :Out of memory! :^C
As noted by Schwern\, this was caused by the new autovivification of array elements under a pattern match:
perl -e '$a[0]=~/x/;print scalar @a'
prints '1' with bleadperl\, '0' with previous releases.
This is caused by Radu Greab's patch: [PATCH perl@11099]Re: [ID 20010704.003] Taint mode breaks global match at: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-07/msg00207.html ... in which it says (in effect) "if the LHS of a pattern match is an array or hash element\, make it an lvalue'.
I also don't understand the implied parallel between the comment: if SV has magic and the code: if SV is an array or hash element but I guess the relationship is the one referred to in pp_helem(): /* This makes C\<local $tied{foo} = $tied{foo}> possible. * Pushing the magical RHS on to the stack is useless\, since * that magic is soon destined to be misled by the local()\, * and thus the later pp_sassign() will fail to mg_get() the * old value. This should also cure problems with delayed * mg_get()s. GSAR 98-07-03 */
Radu\, have you got any ideas on this? We will get subtle breakage in old scripts if this autovivification remains.
Hugo
On Mon\, 3 Dec 2001 02:03 +0000\, Hugo van der Sanden wrote:
Malcolm Hoar \malch@​malch\.com wrote: :perl test.pl :Out of memory! :^C
As noted by Schwern\, this was caused by the new autovivification of array elements under a pattern match:
perl -e '$a[0]=~/x/;print scalar @a'
prints '1' with bleadperl\, '0' with previous releases.
This is caused by Radu Greab's patch: [PATCH perl@11099]Re: [ID 20010704.003] Taint mode breaks global match at: http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-07/msg00207.html ... in which it says (in effect) "if the LHS of a pattern match is an array or hash element\, make it an lvalue'.
I also don't understand the implied parallel between the comment: if SV has magic and the code: if SV is an array or hash element but I guess the relationship is the one referred to in pp_helem(): /* This makes C\<local $tied{foo} = $tied{foo}> possible. * Pushing the magical RHS on to the stack is useless\, since * that magic is soon destined to be misled by the local()\, * and thus the later pp_sassign() will fail to mg_get() the * old value. This should also cure problems with delayed * mg_get()s. GSAR 98-07-03 */
Yes\, my patch was a work around against Sarathy's change described in the above comment.
Radu\, have you got any ideas on this? We will get subtle breakage in old scripts if this autovivification remains.
I'll try to find a better solution to prevent the autovivification.
Thanks\, Radu Greab
p5p@spam.wizbit.be - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#7960 (status was 'resolved')
Searchable as RT7960$