This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
utf8.c: Use memchr instead of strchr
authorKarl Williamson <khw@cpan.org>
Sat, 25 Mar 2017 20:46:50 +0000 (14:46 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 6 Nov 2017 21:31:45 +0000 (14:31 -0700)
This allows things to work properly in the face of embedded NULs.
See the branch merge message for more information.

utf8.c

diff --git a/utf8.c b/utf8.c
index a38f901..c6d08b6 100644 (file)
--- a/utf8.c
+++ b/utf8.c
@@ -5075,7 +5075,7 @@ Perl__swash_to_invlist(pTHX_ SV* const swash)
          * size based on worst possible case, which is each line in the input
          * creates 2 elements in the inversion list: 1) the beginning of a
          * range in the list; 2) the beginning of a range not in the list.  */
-        while ((loc = (strchr(loc, '\n'))) != NULL) {
+        while ((loc = (char *) memchr(loc, '\n', lend - (U8 *) loc)) != NULL) {
             elements += 2;
             loc++;
         }