This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Deparse: make a complex pattern readable with /x
[perl5.git] / doop.c
diff --git a/doop.c b/doop.c
index 7674af5..0a546cc 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -763,9 +763,16 @@ Perl_do_vecget(pTHX_ SV *sv, STRLEN offset, int size)
        Perl_croak(aTHX_ "Illegal number of bits in vec");
 
     if (SvUTF8(sv)) {
-       (void) Perl_sv_utf8_downgrade(aTHX_ sv, TRUE);
-        /* PVX may have changed */
-        s = (unsigned char *) SvPV_flags(sv, srclen, svpv_flags);
+       if (Perl_sv_utf8_downgrade(aTHX_ sv, TRUE)) {
+            /* PVX may have changed */
+            s = (unsigned char *) SvPV_flags(sv, srclen, svpv_flags);
+        }
+        else {
+            Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
+                                "Use of strings with code points over 0xFF as"
+                                " arguments to vec is deprecated. This will"
+                                " be a fatal error in Perl 5.32");
+        }
     }
 
     if (size < 8) {
@@ -913,9 +920,19 @@ Perl_do_vecset(pTHX_ SV *sv)
     STRLEN targlen;
     STRLEN len;
     SV * const targ = LvTARG(sv);
+    char errflags = LvFLAGS(sv);
 
     PERL_ARGS_ASSERT_DO_VECSET;
 
+    /* some out-of-range errors have been deferred if/until the LV is
+     * actually written to: f(vec($s,-1,8)) is not always fatal */
+    if (errflags) {
+        assert(!(errflags & ~(LVf_NEG_OFF|LVf_OUT_OF_RANGE)));
+        if (errflags & LVf_NEG_OFF)
+            Perl_croak_nocontext("Negative offset to vec in lvalue context");
+        Perl_croak_nocontext("Out of memory!");
+    }
+
     if (!targ)
        return;
     s = (unsigned char*)SvPV_force_flags(targ, targlen,