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

Memory corruption? Read-only $_?

From:
Richard Soderberg
Date:
June 29, 2001 05:01
Subject:
Memory corruption? Read-only $_?
Message ID:
Pine.LNX.4.21.0106282003010.29152-100000@oregonnet.com
This applies to 11016, and also occured in 10769 (from memory).

Running the follow perl script under perl-current is giving me some
bizarre error messages that almost scream "pointer" or "buffer
overflow" to my inexperienced eyes.

__PERL__
#!perl-current

sub boom { open(FH, shift) or warn "$!"; while (<FH>) { }; close FH; }

my %files = ( 111111111 => 1 ); # changing the key changes the WEIRD error

my $c; local $d; use vars '$e';

warn 1; for $_ ( keys %files ) { boom $0 } # produces a WEIRD error
warn 2; for $_ ( 1, 2, 3, 4, ) { boom $0 } # change $_ to $a and it works
warn 3; for $b ( keys %files ) { boom $0 } # (no error) special global $b
warn 4; for $c ( keys %files ) { boom $0 } # (no error) my $c
warn 5; for $d ( keys %files ) { boom $0 } # (no error) local $d
warn 6; for $e ( keys %files ) { boom $0 } # (no error) global $e

__OUTPUT__
1 at compare.pl line 9.
Attempt to free non-existent shared string '¨-@¨-@p' at compare.pl line 3.
2 at compare.pl line 10.
Modification of a read-only value attempted at compare.pl line 3.

__END__

For some interesting fun, change the length of the hash key (shorter is
more interesting, though longer is also fun).

It seems to be a bug in $_ somewhere.  I have no idea.

R.




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