diff options
author | Yves Orton <demerphq@gmail.com> | 2023-01-09 21:09:29 +0100 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2023-01-15 17:21:12 +0100 |
commit | 0678333e684b55ba8877db1f865692713dacafc0 (patch) | |
tree | fe5f8a44e747465599ce5209581cae3f215e9283 /t/re | |
parent | 5c6240fadac873b60c46677b4d5b180f4fb6074b (diff) | |
download | perl-0678333e684b55ba8877db1f865692713dacafc0.tar.gz |
regcomp.c - increase size of CURLY nodes so the min/max is a I32
This allows us to resolve a test inconsistency between CURLYX and CURLY
and CURLYM, which have different maximums. We use I32 and not U32 because
the existing count logic uses -1 internally and using an I32 for the min/max
prevents warnings about comparing signed and unsigned values when the
count is compared against the min or max.
Diffstat (limited to 't/re')
-rw-r--r-- | t/re/pat.t | 46 | ||||
-rw-r--r-- | t/re/reg_mesg.t | 2 |
2 files changed, 29 insertions, 19 deletions
diff --git a/t/re/pat.t b/t/re/pat.t index 2ce4ca8764..b0a7b25520 100644 --- a/t/re/pat.t +++ b/t/re/pat.t @@ -350,7 +350,7 @@ sub run_tests { # Defaults assumed if this fails eval { require Config; }; - $::reg_infty = $Config::Config{reg_infty} // 65535; + $::reg_infty = $Config::Config{reg_infty} // ((1<<31)-1); $::reg_infty_m = $::reg_infty - 1; $::reg_infty_p = $::reg_infty + 1; $::reg_infty_m = $::reg_infty_m; # Suppress warning. @@ -358,23 +358,28 @@ sub run_tests { # As well as failing if the pattern matches do unexpected things, the # next three tests will fail if you should have picked up a lower-than- # default value for $reg_infty from Config.pm, but have not. - - is(eval q{('aaa' =~ /(a{1,$::reg_infty_m})/)[0]}, 'aaa', $message); - is($@, '', $message); - is(eval q{('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/}, 1, $message); - is($@, '', $message); - isnt(q{('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/}, 1, $message); - is($@, '', $message); + SKIP: { + skip "REG_INFTY too big to test ($::reg_infty)", 7 + if $::reg_infty > (1<<16); + + is(eval q{('aaa' =~ /(a{1,$::reg_infty_m})/)[0]}, 'aaa', $message); + is($@, '', $message); + is(eval q{('a' x $::reg_infty_m) =~ /a{$::reg_infty_m}/}, 1, $message); + is($@, '', $message); + isnt(q{('a' x ($::reg_infty_m - 1)) !~ /a{$::reg_infty_m}/}, 1, $message); + is($@, '', $message); + + # It should be 'a' x 2147483647, but that exhausts memory on + # reasonably sized modern machines + like('a' x $::reg_infty_m, qr/a{1,}/, + "{1,} matches more times than REG_INFTY"); + } eval "'aaa' =~ /a{1,$::reg_infty}/"; like($@, qr/^\QQuantifier in {,} bigger than/, $message); eval "'aaa' =~ /a{1,$::reg_infty_p}/"; like($@, qr/^\QQuantifier in {,} bigger than/, $message); - # It should be 'a' x 2147483647, but that exhausts memory on - # reasonably sized modern machines - like('a' x $::reg_infty_p, qr/a{1,}/, - "{1,} matches more times than REG_INFTY"); } { @@ -393,12 +398,17 @@ sub run_tests { for my $l (@trials) { # Ordered to free memory my $a = 'a' x $l; - my $message = "Long monster, length = $l"; - like("ba$a=", qr/a$a=/, $message); - unlike("b$a=", qr/a$a=/, $message); - like("b$a=", qr/ba+=/, $message); - - like("ba$a=", qr/b(?:a|b)+=/, $message); + # we do not use like() or unlike() here as the string + # is very long and is not useful if the match fails, + # the useful part + ok("ba$a=" =~ m/a$a=/, sprintf + 'Long monster: ("ba".("a" x %d)."=") =~ m/aa...a=/', $l); + ok("b$a=" !~ m/a$a=/, sprintf + 'Long monster: ("b" .("a" x %d)."=") !~ m/aa...a=/', $l); + ok("b$a=" =~ m/ba+=/, sprintf + 'Long monster: ("b" .("a" x %d)."=") =~ m/ba+=/', $l); + ok("ba$a=" =~ m/b(?:a|b)+=/, sprintf + 'Long monster: ("ba".("a" x %d)."=") =~ m/b(?:a|b)+=/', $l); } } diff --git a/t/re/reg_mesg.t b/t/re/reg_mesg.t index 9a26bdbfde..dc7ec38b55 100644 --- a/t/re/reg_mesg.t +++ b/t/re/reg_mesg.t @@ -108,7 +108,7 @@ sub mark_as_utf8 { return @ret; } -my $inf_m1 = ($Config::Config{reg_infty} || 65535) - 1; +my $inf_m1 = ($Config::Config{reg_infty} || ((1<<31)-1)) - 1; my $inf_p1 = $inf_m1 + 2; my $B_hex = sprintf("\\x%02X", ord "B"); |