diff options
author | Karl Williamson <khw@cpan.org> | 2017-06-30 22:29:36 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2017-07-12 21:14:25 -0600 |
commit | 404a1403f230a499ebbd08ad7ed02da2e30951d9 (patch) | |
tree | 9785889ae5321b79521ca2644dcaaddd9bea289d /ext/XS-APItest/t/utf8_warn_base.pl | |
parent | 57ff5f598ddf7ce8834832a15ba1a4628b5932c4 (diff) | |
download | perl-404a1403f230a499ebbd08ad7ed02da2e30951d9.tar.gz |
APItest/t/utf8_warn_base.pl: Use a default value
This adds a default number of bytes needed to detect overflows, like
previous commits have added defaults for other categories.
Diffstat (limited to 'ext/XS-APItest/t/utf8_warn_base.pl')
-rw-r--r-- | ext/XS-APItest/t/utf8_warn_base.pl | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/ext/XS-APItest/t/utf8_warn_base.pl b/ext/XS-APItest/t/utf8_warn_base.pl index 6c88f5c308..aa9dabf1b7 100644 --- a/ext/XS-APItest/t/utf8_warn_base.pl +++ b/ext/XS-APItest/t/utf8_warn_base.pl @@ -40,6 +40,21 @@ sub requires_extended_utf8($) { return shift > $highest_non_extended_utf8_cp; } +sub overflow_discern_len($) { + + # Returns how many bytes are needed to tell if a UTF-8 sequence is for a + # code point that won't fit in the platform's word size. Only the length + # of the sequence representing a single code point is needed. + + if (isASCII) { + return ($::is64bit) ? 3 : ((shift == $::max_bytes) + ? 1 + : 2); + } + + return ($::is64bit) ? 2 : 8; +} + my @tests; { no warnings qw(portable overflow); @@ -300,7 +315,6 @@ my @tests; : I8_to_native( "\xff\xa0\xa0\xa0\xa0\xa0\xa0\xa4\xa0\xa0\xa0\xa0\xa0\xa0"), ($::is64bit) ? 0x100000000 : -1, # Overflows on 32-bit systems - (isASCII && ! $::is64bit) ? 2 : 1, ], ); @@ -310,7 +324,6 @@ my @tests; [ "overflow that old algorithm failed to detect", "\xfe\x86\x80\x80\x80\x80\x80", -1, - 2, ]; } } @@ -331,7 +344,6 @@ my @tests; : I8_to_native( "\xff\xb0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0"), -1, - (isASCII) ? 3 : 2, ]; if (isASCII) { push @tests, @@ -342,7 +354,6 @@ my @tests; [ "overflow that old algorithm failed to detect", "\xff\x80\x90\x90\x90\xbf\xbf\xbf\xbf\xbf\xbf\xbf\xbf", -1, - 3, ]; } else { @@ -613,6 +624,9 @@ foreach my $test (@tests) { $non_cp_trailing_text = "if you see this, there is an error"; $cp_message_qr = qr/\Q$non_cp_trailing_text\E/; $initially_malformed = 1; + if (! defined $needed_to_discern_len) { + $needed_to_discern_len = overflow_discern_len($length); + } } elsif (requires_extended_utf8($allowed_uv)) { $cp_message_qr = $extended_cp_message_qr; |