This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8n_to_uvchr(): Don't display too many bytes in msg
authorKarl Williamson <khw@cpan.org>
Sat, 17 Jun 2017 23:56:10 +0000 (17:56 -0600)
committerKarl Williamson <khw@cpan.org>
Sun, 2 Jul 2017 15:56:10 +0000 (09:56 -0600)
When raising a message about malformed UTF-8, we shouldn't display bytes
from the next character, unless those bytes were expected to have been
part of the current one.  Tests for this will be added in future commits
in ext/XS-APItest/t/utf8_warn_base.pl

utf8.c

diff --git a/utf8.c b/utf8.c
index ee5405f..e55a6f1 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -1428,7 +1428,7 @@ Perl_utf8n_to_uvchr_error(pTHX_ const U8 *s,
                         if (pack_warn) {
                             message = Perl_form(aTHX_ "%s: %s (overflows)",
                                             malformed_text,
-                                            _byte_dump_string(s0, send - s0, 0));
+                                            _byte_dump_string(s0, curlen, 0));
                         }
                     }
                 }
@@ -1554,7 +1554,7 @@ Perl_utf8n_to_uvchr_error(pTHX_ const U8 *s,
                                 "%s: %s (overlong; instead use %s to represent"
                                 " U+%0*" UVXf ")",
                                 malformed_text,
-                                _byte_dump_string(s0, send - s0, 0),
+                                _byte_dump_string(s0, curlen, 0),
                                 _byte_dump_string(tmpbuf, e - tmpbuf, 0),
                                 ((uv < 256) ? 2 : 4), /* Field width of 2 for
                                                          small code points */