Skip to content
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

Assignment expands arrays #10453

Closed
p5pRT opened this issue Jun 20, 2010 · 7 comments
Closed

Assignment expands arrays #10453

p5pRT opened this issue Jun 20, 2010 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented Jun 20, 2010

Migrated from rt.perl.org#75888 (status was 'rejected')

Searchable as RT75888$

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2010

From @yecril71pl

Created by @yecril71pl

The documentation on assignment operator is incomplete.

PERLOP(1) Perl Programmers Reference Guide PERLOP(1)
Assignment Operators

  "=" is the ordinary assignment operator.

  Assignment operators work as in C. That is,

No, they do not, in one special case​:

#!/usr/bin/perl -w
use strict; use warnings; my @​a; ($a [01000], $,, $\) = (0, ',', '
'); print @​a;

This code, mutatis mutandis, smashes the stack in C.
OTOH, the assignment to an array element that is off-bounds causes Perl to
expand the array, and wastes memory if the index of the element is large.

AFAIK, this behaviour is described nowhere in perl documentation. It is also
different from how it works in shell or in javascript so I think it would be
worth saying.

Perl Info

Flags:
    category=docs
    severity=high

This perlbug was built using Perl 5.10.0 - Wed Mar 24 11:39:55 UTC 2010
It is being executed now by  Perl 5.10.0 - Wed Mar 24 11:34:27 UTC 2010.

Site configuration information for perl 5.10.0:

Configured by abuild at Wed Mar 24 11:34:27 UTC 2010.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.31, archname=x86_64-linux-thread-multi
    uname='linux build32 2.6.31 #1 smp 2010-01-06 16:07:25 +0100 x86_64 x86_64 
x86_64 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl 
-Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-
fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-
tables -fasynchronous-unwind-tables -g -Wall -pipe -Accflags=-
DPERL_USE_SAFE_PUTENV'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -
DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64',
    optimize='-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-
protector -funwind-tables -fasynchronous-unwind-tables -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DPERL_USE_SAFE_PUTENV -DDEBUGGING -
fno-strict-aliasing -pipe'
    ccversion='', gccversion='4.4.1 [gcc-4_4-branch revision 150839]', 
gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib64'
    libpth=/lib64 /usr/lib64 /usr/local/lib64
    libs=-lm -ldl -lcrypt -lpthread
    perllibs=-lm -ldl -lcrypt -lpthread
    libc=/lib64/libc-2.10.1.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.10.1'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-
rpath,/usr/lib/perl5/5.10.0/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib64'

Locally applied patches:
    


@INC for perl 5.10.0:
    /usr/lib/perl5/5.10.0/x86_64-linux-thread-multi
    /usr/lib/perl5/5.10.0
    /usr/lib/perl5/site_perl/5.10.0/x86_64-linux-thread-multi
    /usr/lib/perl5/site_perl/5.10.0
    /usr/lib/perl5/vendor_perl/5.10.0/x86_64-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.10.0
    /usr/lib/perl5/vendor_perl
    .


Environment for perl 5.10.0:
    HOME=/home/krzysztof
    LANG=pl_PL.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH=/usr/lib64/mpi/gcc/openmpi/lib64
    LOGDIR (unset)
    PATH=/usr/lib64/mpi/gcc/openmpi/bin:/home/krzysztof/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib64/jvm/jre/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2010

From @demerphq

On 20 June 2010 14​:11, Kristof Zelechovski <perlbug-followup@​perl.org> wrote​:

# New Ticket Created by  Kristof Zelechovski
# Please include the string​:  [perl #75888]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=75888 >

This is a bug report for perl from giecrilj@​stegny.2a.pl,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]
The documentation on assignment operator is incomplete.

PERLOP(1)              Perl Programmers Reference Guide              PERLOP(1)
Assignment Operators

      "=" is the ordinary assignment operator.

      Assignment operators work as in C.  That is,

No, they do not, in one special case​:

#!/usr/bin/perl -w
use strict; use warnings; my @​a; ($a [01000], $,, $\) = (0, ',', '
'); print @​a;

This code, mutatis mutandis, smashes the stack in C.

Im not convinced this is relevant. as it is arguable that C doesn't
have real arrays at all, instead providing only pointers and some
syntactic sugar to make you think you are dealing with a first class
object, when in fact you are dealing with a pointer to memory with
each element having a predetermined size in terms of bytes. That ain't
an array, its a convention.

Perl on the other hand has a first class array concept. It does not
allocate arrays off the stack. Actually perl allocates almost nothing
off the stack, but thats another point entirely. :-)

OTOH, the assignment to an array element that is off-bounds causes Perl to

"off bounds"?!?

Where did you declare the size of the array? You didnt, because you
cant, because there is no such thing as "off bounds".

expand the array, and wastes memory if the index of the element is large.

Mostly this is considered a feature.

AFAIK, this behaviour is described nowhere in perl documentation.  It is also
different from how it works in shell or in javascript so I think it would be
worth saying.

I could have sworn it is documented, however poking around the closest
i could find was heavy implication that it is the case in things like
perldata, perldsc and perlref.

I was actually quite shocked about how useless perldata as a resource
is. It doesnt document arrays or hashes explicitly at all, but spends
a ridiculous amount of time explaining lists and discussing hashes and
arrays in the context of List and Scalar values. Perlintro has a basic
introduction to arrays and hashes, but doesnt document what you think
should be documented, and contains the line

"Scalars, arrays and hashes are documented more fully in perldata."

to which i can only add "not in the version i just read".

Absent finding some other perldoc that specifies this I concur that
this is a documentation "bug" that should be fixed. Perldata seriously
needs some love IMO.

cheers,
Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2010

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 14, 2010

From @yecril71pl

On Pon. 21 Cze. 2010, 03​:36​:59, demerphq wrote​:

OTOH, the assignment to an array element that is off-bounds causes
Perl to

"off bounds"?!?

Where did you declare the size of the array? You didnt, because you
cant, because there is no such thing as "off bounds".

If the array has 10 elements at present and I assign to element #11, it
is just off bounds. If I assign to element #100000000000, it is a DOS
attack on VM.

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2012

From @jkeenan

On Sun Jun 20 05​:11​:12 2010, yecril71pl wrote​:

This is a bug report for perl from giecrilj@​stegny.2a.pl,
generated with the help of perlbug 1.36 running under perl 5.10.0.

The documentation on assignment operator is incomplete.

PERLOP(1) Perl Programmers Reference Guide
PERLOP(1)
Assignment Operators

   "=" is the ordinary assignment operator\.

   Assignment operators work as in C\.  That is\,

No, they do not, in one special case​:

#!/usr/bin/perl -w
use strict; use warnings; my @​a; ($a [01000], $,, $\) = (0, ',', '
'); print @​a;

This code, mutatis mutandis, smashes the stack in C.
OTOH, the assignment to an array element that is off-bounds causes
Perl to
expand the array, and wastes memory if the index of the element is
large.

AFAIK, this behaviour is described nowhere in perl documentation. It
is also
different from how it works in shell or in javascript so I think it
would be
worth saying.

[Please do not change anything below this line]

I recommend that this ticket be closed. No patch was ever submitted,
and in other RTs we can find patches for the same section in 'perlop'
discussed in this ticket.

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Mar 29, 2012

From @jkeenan

On Wed Mar 28 18​:44​:56 2012, jkeenan wrote​:

and in other RTs we can find patches for the same section in 'perlop'
discussed in this ticket.

E.g., https://rt-archive.perl.org/perl5/Ticket/Display.html?id=68312

@p5pRT
Copy link
Author

p5pRT commented Apr 5, 2012

@rjbs - Status changed from 'open' to 'rejected'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant