develooper Front page | perl.perl5.porters | Postings from July 2001

[ID 20010712.005] Perl bug with "delete" on arrays

Thread Next
From:
Andrew C. Ryan
Date:
July 12, 2001 13:13
Subject:
[ID 20010712.005] Perl bug with "delete" on arrays
Message ID:
200107122012.PAA25725@bohr.celoxnetworks.com

This is a bug report for perl from acryan@celoxnetworks.com,
generated with the help of perlbug 1.28 running under perl v5.6.0.


-----------------------------------------------------------------
[Please enter your report here]



Larry,

According to the man page on perl.com and the description given in Programming Perl, 3rd edtion, for Perl's delete() function, "delete $a[$#a];" 
should be equivalent to "$#a--".  But it looks like the delete, when used on the last elements of arrays, has a bug, because at the end of program, 
when the garbage collector is cleaned up befow exiting, it gives a "Attempt to free unreferenced scalar." error for each time a statement like "delete 
$a[$#a];" is executed.  Below, I give the PERL version and a couple of one-line programs to illustrate the bug.

-- Andrew



$ perl -v

This is perl, v5.6.0 built for sun4-solaris

Copyright 1987-2000, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

$ perl -e 'use strict; my @a = (1, 2, 3); $#a--; $a[4] = 5; print "@a\n";'
1 2   5
$ perl -e 'use strict; my @a = (1, 2, 3); delete $a[$#a]; $a[4] = 5; print "@a\n";'
1 2 5  5
Attempt to free unreferenced scalar.
$



[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl v5.6.0:

Configured by nhogan at Wed Jun  7 14:51:45 CDT 2000.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=solaris, osvers=2.8, archname=sun4-solaris
    uname='sunos einstein 5.8 generic sun4u sparc sunw,ultra-enterprise '
    config_args='-Accflags=-DPERL_POLLUTE -Uusedl -Dcc=gcc -Dprefix=/celox'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.8.1
    cppflags='-DPERL_POLLUTE -I/usr/local/include'
    ccflags ='-DPERL_POLLUTE -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
    libs=-lsocket -lnsl -lgdbm -ldl -lm -lc -lcrypt -lsec
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_none.xs, dlext=none, d_dlsymun=undef, ccdlflags=''
    cccdlflags='', lddlflags=''

Locally applied patches:
    

---
@INC for perl v5.6.0:
    /celox/lib/perl5/5.6.0/sun4-solaris
    /celox/lib/perl5/5.6.0
    /celox/lib/perl5/site_perl/5.6.0/sun4-solaris
    /celox/lib/perl5/site_perl/5.6.0
    /celox/lib/perl5/site_perl/5.005/sun4-solaris
    /celox/lib/perl5/site_perl/5.005
    /celox/lib/perl5/site_perl
    .

---
Environment for perl v5.6.0:
    HOME=/home/acryan
    LANG (unset)
    LANGUAGE (unset)
    LC_COLLATE=en_US.ISO8859-1
    LC_CTYPE=en_US.ISO8859-1
    LC_MESSAGES=C
    LC_MONETARY=en_US.ISO8859-1
    LC_NUMERIC=en_US.ISO8859-1
    LC_TIME=en_US.ISO8859-1
    LD_LIBRARY_PATH=/usr/local/lib/:/usr/local/lib/X11/:/usr/X11R6/LessTif/Motif1.2/lib/
    LOGDIR (unset)
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/openwin/bin:/usr/ucb:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/openwin/bin:/usr/ucb:/usr/bin:/home/acryan/bin:/home/acryan/Zeus/bin:/opt/synopsys/sparcOS5/syn/bin:/opt/vcs5.1/sun_sparc_solaris_5.5.1/bin:/usr/local/bin/mibtools:/home/acryan/tip/PIE/system_sim/bin:/home/acryan/bin:/home/acryan/Zeus/bin:/opt/synopsys/sparcOS5/syn/bin:/opt/vcs5.1/sun_sparc_solaris_5.5.1/bin:/usr/local/bin/mibtools:/home/acryan/tip/PIE/system_sim/bin:/home/acryan/tip/Celox_48000/tools/bin
    PERL_BADLANG (unset)
    SHELL=/usr/local/bin/tcsh


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About