develooper Front page | perl.perl5.porters | Postings from January 2012

Re: [perl #27392] 5.8.2 cores or loops using hashref as subscript

From:
Karl Williamson
Date:
January 29, 2012 13:10
Subject:
Re: [perl #27392] 5.8.2 cores or loops using hashref as subscript
Message ID:
4F25B5AC.8010105@khwilliamson.com
On 01/29/2012 01:56 PM, Dave Mitchell wrote:
> On Fri, Jan 27, 2012 at 07:50:25PM -0800, James E Keenan via RT wrote:
>> I reviewed this older ticket tonight.  Trimming the last post:
>>
>> #####
>> On Fri Mar 05 04:19:24 2004, keni@aol.net wrote:
>> ...
>>> I agree - my code was in error.  But I don't like being able to core
>>> an interpreter (and not get any indication of why).
>>>
>>
>> So it appears the OP concedes he was attempting something he should not
>> have.  When I run the attached program -- which throws 'use strict' and
>> 'use warnings' around the OP's code -- I get:
>>
>> #####
>> $ perl 27393.pl
>> Useless use of hash element in void context at 27393.pl line 10.
>> X: 1
>> X: HASH(0x1804180)
>> Use of reference "HASH(0x1804180)" as array index at 27393.pl line 10.
>> Use of uninitialized value $_ in concatenation (.) or string at 27393.pl
>> line 9.
>> X:
>> Use of uninitialized value $_ in array element at 27393.pl line 10.
>> Can't use string ("1") as a HASH ref while "strict refs" in use at
>> 27393.pl line 10.
>> #####
>>
>> So I am amply warned of my bad behavior.  I recommend we close this ticket.
>
> I disagree. The OP pointed out that the code segfaulted. Bad perl code
> shouldn't segfault. There appear to be a couple of possible issues;
>
> The first is modifying (extending) the array be looped over; this has
> traditionally been regarded as a Bad Thing to do, although I think we
> handle this now.
>
> The second issue is that doing $array[$ref] numfies the address of $ref
> and so indexes a huge array element. I think the OP's code was segfaulting
> when doing address calculations that overflowed a 32-bit address.
> IIRC, we've since hardened the array indexing code to be more robust against
> this sort of thing.
>
> So, I think we've *probably* fixed this. but it would be nice if someone
> could bisect this.
>
> It might be as simple as, doing on a 32-bit system), $a[1073840232]
> (based on the OP's stack trace).
>

I run on a 32 bit system, and I ran this
perl5.8.9 -e 'print $a[1073840232]'
Name "main::a" used only once: possible typo at -e line 1.
Use of uninitialized value in print at -e line 1.

which is the earliest perl version I have.



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