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

[perl #118691] Perl crash on usage of ndex [-1] for array in subroutine call

From:
Wolf-Dietrich Moeller
Date:
July 2, 2013 19:39
Subject:
[perl #118691] Perl crash on usage of ndex [-1] for array in subroutine call
Message ID:
rt-3.6.HEAD-2552-1372514093-1051.118691-75-0@perl.org
# New Ticket Created by  Wolf-Dietrich Moeller 
# Please include the string:  [perl #118691]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=118691 >


Hi,
the following behaviour of Perl looks like a bug to me:

In the test program below, the third and fourth call to the subroutine
should behave equal, i.e. the fourth call should not result in a crash of
Perl with the following message:
"Modification of non-creatable array value attempted, subscript -1 at <PATH
TO PERL PROGRAM> line 17."

Reason for my assumption is that the  " // undef" in the first call and the
third call to "func" should be superfluous, as the non-existing array
element should return "undef" anyhow. Thus the third call and the fourth
call should behave identical.

Test program:
########################################
# Test program to show crash of Perl in the fourth call to 'sub func'
# Such crash seems to happen only when the index is negative and the array
element does not exist.
# For positive indices no crash, even if the array element does not exist.
use strict;
sub func ($) { my $val = shift; print $val // 'undef'," in sub func\n" }
my @array;
my $x = $array[0];
my $y = $array[-1];
print '@array[0,-1] : ',join(' ',map $_ // 'undef',$x,$y)," in main\n";
print '($array[0] // undef) :',"\n";
func ($array[0] // undef);
print '($array[0]) :',"\n";
func ($array[0]);
print '($array[-1] // undef) :',"\n";
func ($array[-1] // undef);
print '($array[-1]) :',"\n";
func ($array[-1]);
###########################################

The output of the test program is:
@array[0,-1] : undef undef in main
($array[0] // undef) :
undef in sub func
($array[0]) :
undef in sub func
($array[-1] // undef) :
undef in sub func
($array[-1]) :
Modification of non-creatable array value attempted, subscript -1 at <PATH
TO PERL PROGRAM> line 17.

#############################################

My system is Win XP, Service pack 3, and I currently use the Perl
distribution from ActiveState
"ActivePerl-5.16.3.1603-MSWin32-x86-296746.msi".
Searching for 'array' in the new and open bugs lists did not result in a
similar bug report, thus I assume this was not reported before.

Thanks
Wolf

PS.
Sorry I did not use the recommended tools for version reporting, as nowadays
I only have access to Windows environment with ActiveState Perl windows
binary.
I know that I normally should report this bug to ActiveState, but I have the
bad experience, that ActiveState did not respond on a bug report at all
(which was handled immediately by you, when I sent it to you later).
Thus I send this bug report directly to you, as I assume that this bug is
not a problem of the Windows port, but of the basic Perl as provided by
perl.org.

----------------------------------------
Dr. Wolf-Dietrich Moeller
D-81739 M√ľnchen, Germany
mailto:wolf-dietrich_moeller@t-online.de





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