This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix the I32 bug for index() and rindex()
[perl5.git] / t / bigmem / index.t
1 #!perl
2 BEGIN {
3     chdir 't';
4     unshift @INC, "../lib";
5 }
6
7 use strict;
8 require './test.pl';
9 use Config qw(%Config);
10
11 # memory usage checked with top
12 $ENV{PERL_TEST_MEMORY} >= 2
13     or skip_all("Need ~2GB for this test");
14 $Config{ptrsize} >= 8
15     or skip_all("Need 64-bit pointers for this test");
16
17 plan(tests => 4);
18
19 my $space = " "; # avoid constant folding from doubling memory usage
20 # concatenation here increases memory usage significantly
21 my $work = $space x 0x80000002;
22 substr($work, 0x80000000) = "\n\n";
23
24 # this would SEGV
25 is(index($work, "\n"), 0x80000000, "test index() over 2G mark");
26
27 # this would simply fail
28 is(rindex($work, "\n"), 0x80000001, "test rindex() over 2G mark");
29
30 utf8::upgrade($work);
31
32 # this would SEGV
33 is(index($work, "\n"), 0x80000000, "test index() over 2G mark (utf8-ish)");
34
35 # this would simply fail
36 is(rindex($work, "\n"), 0x80000001, "test rindex() over 2G mark (utf8-ish)");
37