[perl #30979] Array indices wrap around at 2**32
by Andy Lyttle (via RT) other posts by this author
Aug 7 2004 5:26AM messages near this date
Smoke [] 23200 FAIL(F) openbsd 3.5 (i386/1 cpu)
|
Re: [perl #30979] Array indices wrap around at 2**32
# New Ticket Created by Andy Lyttle
# Please include the string: [perl #30979]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=30979 >
Attempting to access an array element using a very large value for the
index
yields weird results, particularly near [2**32]. See this test case:
#!/usr/bin/perl
use strict;
use warnings;
my @array=qw(a b c d e f g);
for(my $x=7;$x> 0;$x--) {
print $array[2**32-$x];
}
print "\n";
It looks like 2**32 is behaving like 0, so [2**32-7] is equivalent to
[-7].
However, if we use index values greater than 2**32, we get the last
element
('g'). Expected behavior is to return undef and warn "Use of
uninitialized
value", and not wrap around at all, because that's the sort of weird
behavior
we expect from C, not from perl.
Reproduced with Perl 5.8.1 on Mac OS X and 5.6.1 on Linux (x86).
---
Flags:
category=
severity=
---
Site configuration information for perl v5.8.1:
Configured by root at Fri Sep 12 19:46:46 PDT 2003.
Summary of my perl5 (revision 5.0 version 8 subversion 1 RC3)
configuration:
Platform:
osname=darwin, osvers=7.0, archname=darwin-thread-multi-2level
uname='darwin hampsten 7.0 darwin kernel version 6.0: fri jul 25
16:58:41 pdt 2003;
root:xnu-344.frankd.rootsxnu-344.frankd~objrelease_ppc power macintosh
powerpc '
config_args='-ds -e -Dprefix=/usr -Dccflags=-g -pipe
-Dldflags=-Dman3ext=3pm -Duseithreads -Duseshrplib'
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=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-g -pipe -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include',
optimize='-Os',
cppflags='-no-cpp-precomp -g -pipe -pipe -fno-common -DPERL_DARWIN
-no-cpp-precomp -fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='3.3 20030304 (Apple Computer, Inc. build
1495)', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='MACOSX_DEPLOYMENT_TARGET=10.3 cc', ldflags ='-L/usr/local/lib'
libpth=/usr/local/lib /usr/lib
libs=-ldbm -ldl -lm -lc
perllibs=-ldl -lm -lc
libc=/usr/lib/libc.dylib, so=dylib, useshrplib=true,
libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dyld.xs, dlext=bundle, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-bundle -undefined dynamic_lookup
-L/usr/local/lib'
Locally applied patches:
RC3
---
@INC for perl v5.8.1:
/System/Library/Perl/5.8.1/darwin-thread-multi-2level
/System/Library/Perl/5.8.1
/Library/Perl/5.8.1/darwin-thread-multi-2level
/Library/Perl/5.8.1
/Library/Perl
/Network/Library/Perl/5.8.1/darwin-thread-multi-2level
/Network/Library/Perl/5.8.1
/Network/Library/Perl
.
---
Environment for perl v5.8.1:
DYLD_LIBRARY_PATH (unset)
HOME=/Users/phroggy
LANG (unset)
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/Users/phroggy/bin
PERL_BADLANG (unset)
SHELL=/bin/bash
Thread:
Andy Lyttle (via RT)
John Peacock
|