This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #130567] Assertion failure in scan_const
[perl5.git] / toke.c
diff --git a/toke.c b/toke.c
index 3a603e1..61ea45d 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -701,6 +701,8 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
 {
     const char *s = NULL;
     yy_parser *parser, *oparser;
+    const U8* first_bad_char_loc;
+
     if (flags && flags & ~LEX_START_FLAGS)
        Perl_croak(aTHX_ "Lexing code internal error (%s)", "lex_start");
 
@@ -743,6 +745,18 @@ Perl_lex_start(pTHX_ SV *line, PerlIO *rsfp, U32 flags)
     if (line) {
        STRLEN len;
        s = SvPV_const(line, len);
+
+        if (SvUTF8(line) && ! is_utf8_string_loc((U8 *) s,
+                                                 SvCUR(line),
+                                                 &first_bad_char_loc))
+        {
+            _force_out_malformed_utf8_message(first_bad_char_loc,
+                                              (U8 *) s + SvCUR(line),
+                                              0,
+                                              1 /* 1 means die */ );
+            NOT_REACHED; /* NOTREACHED */
+        }
+
        parser->linestr = flags & LEX_START_COPIED
                            ? SvREFCNT_inc_simple_NN(line)
                            : newSVpvn_flags(s, len, SvUTF8(line));