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
segmentation fault modifying array ref during push #9776
Comments
From dan@gina.alaska.eduCreated by dan@gina.alaska.eduThe following program causes a segmentation fault: #!/usr/bin/perl use strict; my $x; push @$x, abc(); sub abc { ##### $ gdb --args perl crash.pl I am using Fedora 11. Perl Info
|
From nj88udd02@sneakemail.comHi all, dan@gina.alaska.edu (via RT) wrote:
Confirmed with blead at 3244086. Cheers, |
The RT System itself - Status changed from 'new' to 'open' |
From perl@profvince.comThis happens because the array referenced by $x is pushed on the stack, Note that replacing push by a prototyped sub doesn't segfault : sub def (\@$) { print @{$_[0]} } This will print "1", because the first argument is actually a new our $global; In any case, it's not consistent with push() where you pass the array Vincent. |
From @davidnicolI shrunk the demonstration a little for addition to t/op/list.t. Inline Patchdiff --git a/t/op/list.t b/t/op/list.t
index a8fdc18..b678224 100644
--- a/t/op/list.t
+++ b/t/op/list.t
@@ -6,7 +6,7 @@ BEGIN {
}
require "test.pl";
-plan( tests => 57 );
+plan( tests => 59 );
@foo = (1, 2, 3, 4);
cmp_ok($foo[0], '==', 1, 'first elem');
@@ -161,3 +161,21 @@ cmp_ok(join('',(1,2),3,(4,5)),'eq','12345','list
+{ |
From @davidnicol
On the other hand, that subroutine arguments are all aliases and that With the \@@ prototype it goes in the earlier array too. With the cat 66930_where_does_it_go.pl sub mypush(\@@) { my $ref = shift; push @$ref, @_ } @before=@after=(); @before=@after=(); @before=@after=(); sub mypush2 { my $ref = shift; push @$ref, @_ } |
From @davidnicolStunningly, unshift doesn't have the segfault problem. Like push that I wonder if a note about this edge case of parameter ordering being pp_push and pp_unshift in pp.c are very similar. Hmm. 5.10.0 (standard cygwin) segfaults on push but not unshift. 5.8.8 (debian package) segfaults on both. Current blead on linux allows push, complains and aborts on unshift, Inline Patchdiff --git a/pp.c b/pp.c
index 9cedc3f..9318755 100644
--- a/pp.c
+++ b/pp.c
@@ -4549,6 +4549,7 @@ PP(pp_push)
}
}
else {
+ Perl_warn(aTHX_ "inside push refcount %i", SvREFCNT((SV*) ary));
PL_delaymagic = DM_DELAY;
for (++MARK; MARK <= SP; MARK++) {
SV * const sv = newSV(0);
@@ -4596,17 +4597,23 @@ PP(pp_unshift)
SPAGAIN;
}
else {
+ Perl_warn(aTHX_ "inside unshift refcount %i", SvREFCNT((SV*) ary));
register I32 i = 0;
av_unshift(ary, SP - MARK);
+ Perl_warn(aTHX_ "unshifted %i", SP - MARK);
while (MARK < SP) {
+ Perl_warn(aTHX_ "unshifting %i", SP - MARK);
SV * const sv = newSVsv(*++MARK);
+ Perl_warn(aTHX_ "unshifting %i", SP - MARK);
(void)av_store(ary, i++, sv);
+ Perl_warn(aTHX_ "unshifting %i", SP - MARK);
}
}
SP = ORIGMARK;
if (GIMME_V != G_VOID) {
PUSHi( AvFILL(ary) + 1 );
}
+ Perl_warn(aTHX_ "returning");
RETURN;
}
diff --git a/utils/Makefile b/utils/Makefile
This is perl, v5.11.0 (GitLive-blead-g7f6de3f*) built for i686-linux perlhacker@catnip:~/perl$ ./perl -le '$x=[]; push @$x, (sub {$x="";"pbth"})->()' |
From @iabynWithout looking at this thread in detail (I just haven't got time at the On Sun, Jun 28, 2009 at 07:59:48PM -0500, David Nicol wrote:
-- |
From @davidnicolOn Tue, Jun 30, 2009 at 7:54 AM, Dave Mitchell <davem@iabyn.com> wrote:
While it is true that this bug is clearly of the "so don't do that" variety, While a refcounted stack might prevent freeing the no-longer-referenced Don't we want to normalize the builtins to use the prototyped calling |
From @jimc
Id suspect that its more like: These are problems that are understood, if not by everyone, Im unconvinced that fixing 70% of the bugs I dont understand Wisdom (self-preservation?) says stay the hell out of the minefield, Then theres that "we" in there. |
From @iabynOn Thu, Jul 02, 2009 at 07:22:45PM -0500, David Nicol wrote:
You appear to be conflating "it doesn't segfault" with "there's nothing Anyway, as I said before, I haven't got time to discuss this now. -- |
Migrated from rt.perl.org#66930 (status was 'open')
Searchable as RT66930$
The text was updated successfully, but these errors were encountered: