Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.94k stars 554 forks source link

Coredump when shortening an array during use #6874

Open p5pRT opened 20 years ago

p5pRT commented 20 years ago

Migrated from rt.perl.org#24342 (status was 'open')

Searchable as RT24342$

p5pRT commented 20 years ago

From perl-5.8.0@ton.iguana.be

Created by perl-5.8.0@ton.iguana.be

perl -wle '$a=@​F[4\,7]-=@​F=3' Segmentation fault (core dumped)

Perl Info ``` Flags: category=core severity=low Site configuration information for perl v5.8.0: Configured by ton at Tue Nov 12 01:56:18 CET 2002. Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration: Platform: osname=linux, osvers=2.4.19, archname=i686-linux-thread-multi-64int-ld uname='linux quasar 2.4.19 #5 wed oct 2 02:34:25 cest 2002 i686 unknown ' config_args='' hint=recommended, useposix=true, d_sigaction=define usethreads=define use5005threads=undef useithreads=define usemultiplicity=define useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=define use64bitall=undef uselongdouble=define usemymalloc=y, bincompat5005=undef Compiler: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2 -fomit-frame-pointer', cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='2.95.3 20010315 (release)', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lnsl -lndbm -ldb -ldl -lm -lpthread -lc -lposix -lcrypt -lutil perllibs=-lnsl -ldl -lm -lpthread -lc -lposix -lcrypt -lutil libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.2.4' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: @INC for perl v5.8.0: /usr/lib/perl5/5.8.0/i686-linux-thread-multi-64int-ld /usr/lib/perl5/5.8.0 /usr/lib/perl5/site_perl/5.8.0/i686-linux-thread-multi-64int-ld /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl . Environment for perl v5.8.0: HOME=/home/ton LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/ton/bin.Linux:/home/ton/bin:/home/ton/bin.SampleSetup:/usr/local/bin:/usr/local/sbin:/usr/local/jre/bin:/home/oracle/product/9.0.1/bin:/usr/local/ar/bin:/usr/games/bin:/usr/X11R6/bin:/usr/share/bin:/usr/bin:/usr/sbin:/bin:/sbin:. PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 20 years ago

From @rgs

perl-5.8.0@​ton.iguana.be (via RT) wrote​:

perl -wle '$a=@​F[4\,7]-=@​F=3' Segmentation fault (core dumped)

Could someone explain why this is allowed at all ? Why can I apply -= to an array slice but not to an array ?

  $ ./perl -wle '@​x=(1..5);@​x[1\,2]-=3;print for@​x'   1   2   0   4   5

  $ ./perl -wle '@​x=(1..5);@​x-=3;print for@​x'   Can't modify array dereference in subtraction (-) at -e line 1\, near "3;"   Execution of -e aborted due to compilation errors.

p5pRT commented 20 years ago

From @rgs

Going to answer my own question :

Could someone explain why this is allowed at all ? Why can I apply -= to an array slice but not to an array ?

Hm\, probably for compatibility with the (mistaken) use of a one-element slice as an array element.

  @​x[2] -= 3;

p5pRT commented 20 years ago

From @iabyn

On Wed\, Oct 29\, 2003 at 09​:58​:02AM +0100\, Rafael Garcia-Suarez wrote​:

Going to answer my own question :

Could someone explain why this is allowed at all ? Why can I apply -= to an array slice but not to an array ?

Hm\, probably for compatibility with the (mistaken) use of a one-element slice as an array element.

@​x\[2\] \-= 3;

Surely its just the normal 'last element returned' behaviour of a list in scalar context\, eg

$ perl5.8.1 -le'$a=1;$b=2;($a\,$b)+=10; print "$a $b"' 1 12 $ perl5.8.1 -le'$a=1;$b=2;@​c=(($a\,$b)+=10); print "$a $b; @​c"' 1 12; 12

-- You live and learn (although usually you just live).

p5pRT commented 20 years ago

From Michael.Jacob@SCHERING.DE

Could someone explain why this is allowed at all ? Why can I apply -= to an array slice but not to an array ?

Hm\, probably for compatibility with the (mistaken) use of a one-element slice as an array element.

@​x[2] -= 3;

Surely its just the normal 'last element returned' behaviour of a list in scalar context\, eg

Its not 'returned'\, its 'propagated'. It seems a list will return an alias to the last element. It further seems the element is not REFCOUNT++ed (same as with @​_) and that this alias is retrieved before the right hand side of the expression is evaluated.

So it's clear​:

1.) find LVALUE fro left hand side 1.1) evaluate array slice 1.2) create $F[0] to $F[7] on first access 1.3) return alias to $F[7] from list 2.) evaluate RVALUE from right hand side 2.1) fill array with new value 3 2.2.1) set $F[0] to 3 2.2.2) DESTROY $F[1] to $F[$#F] 3.) assign 3 via alias to destroyed SV 3.1) coredump

Michael Jacob

p5pRT commented 20 years ago

From @chipdude

According to Michael.Jacob@​SCHERING.DE​:

It seems a list will return an alias to the last element. It further seems the element is not REFCOUNT++ed (same as with @​_) and that this alias is retrieved before the right hand side of the expression is evaluated.

"Bob"dammit! Not another stack refcount bug!

Sorry about that. It's just fricking irritating that the stack still doesn't refcount its contents. -- Chip Salzenberg - a.k.a. - \chip@​pobox\.com "I wanted to play hopscotch with the impenetrable mystery of existence\,   but he stepped in a wormhole and had to go in early." // MST3K

p5pRT commented 19 years ago

From @smpeters

[chip - Wed Oct 29 13​:54​:58 2003]​:

According to Michael.Jacob@​SCHERING.DE​:

It seems a list will return an alias to the last element. It further seems the element is not REFCOUNT++ed (same as with @​_) and that this alias is retrieved before the right hand side of the expression is evaluated.

"Bob"dammit! Not another stack refcount bug!

Sorry about that. It's just fricking irritating that the stack still doesn't refcount its contents.

Well\, recent changes have caught the coredump. Now\, bleadperl is just panicking instead.

./perl -wle '$a=@​F[4\,7]-=@​F=3' Name "main​::a" used only once​: possible typo at -e line 1. panic​: sv_upgrade to unknown type 255 at -e line 1.