This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Silence (stupid) compiler warning
[perl5.git] / doop.c
diff --git a/doop.c b/doop.c
index 3cb1354..2c85c83 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -46,6 +46,10 @@ S_do_trans_simple(pTHX_ SV * const sv, const OPtrans_map * const tbl)
     U8 * const send = s+len;
 
     PERL_ARGS_ASSERT_DO_TRANS_SIMPLE;
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_simple:"
+                                          " input sv:\n",
+                                          __FILE__, __LINE__));
+    DEBUG_y(sv_dump(sv));
 
     /* First, take care of non-UTF-8 input strings, because they're easy */
     if (!SvUTF8(sv)) {
@@ -101,6 +105,9 @@ S_do_trans_simple(pTHX_ SV * const sv, const OPtrans_map * const tbl)
        SvUTF8_on(sv);
        SvSETMAGIC(sv);
     }
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+                                          __FILE__, __LINE__, matches));
+    DEBUG_y(sv_dump(sv));
     return matches;
 }
 
@@ -127,6 +134,11 @@ S_do_trans_count(pTHX_ SV * const sv, const OPtrans_map * const tbl)
 
     PERL_ARGS_ASSERT_DO_TRANS_COUNT;
 
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_count:"
+                                          " input sv:\n",
+                                          __FILE__, __LINE__));
+    DEBUG_y(sv_dump(sv));
+
     if (!SvUTF8(sv)) {
        while (s < send) {
             if (tbl->map[*s++] >= 0)
@@ -147,6 +159,8 @@ S_do_trans_count(pTHX_ SV * const sv, const OPtrans_map * const tbl)
        }
     }
 
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: count returning %zu\n",
+                                          __FILE__, __LINE__, matches));
     return matches;
 }
 
@@ -170,6 +184,11 @@ S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl)
 
     PERL_ARGS_ASSERT_DO_TRANS_COMPLEX;
 
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_complex:"
+                                          " input sv:\n",
+                                          __FILE__, __LINE__));
+    DEBUG_y(sv_dump(sv));
+
     if (!SvUTF8(sv)) {
        U8 *d = s;
        U8 * const dstart = d;
@@ -293,6 +312,9 @@ S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl)
        SvUTF8_on(sv);
     }
     SvSETMAGIC(sv);
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+                                          __FILE__, __LINE__, matches));
+    DEBUG_y(sv_dump(sv));
     return matches;
 }
 
@@ -323,6 +345,14 @@ S_do_trans_count_invmap(pTHX_ SV * const sv, AV * const invmap)
 
     PERL_ARGS_ASSERT_DO_TRANS_COUNT_INVMAP;
 
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d:"
+                                          "entering do_trans_count_invmap:"
+                                          " input sv:\n",
+                                          __FILE__, __LINE__));
+    DEBUG_y(sv_dump(sv));
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "mapping:\n"));
+    DEBUG_y(invmap_dump(from_invlist, (UV *) SvPVX(to_invmap_sv)));
+
     s = (U8*)SvPV_nomg(sv, len);
 
     send = s + len;
@@ -356,10 +386,11 @@ S_do_trans_count_invmap(pTHX_ SV * const sv, AV * const invmap)
         s += s_len;
     }
 
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+                                          __FILE__, __LINE__, matches));
     return matches;
 }
 
-
 /* Helper function for do_trans().
  * Handles cases where an inversion map implementation is to be used and the
  * search and replacement charlists are either not identical or flags are
@@ -390,8 +421,8 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
     const bool delete_unfound = cBOOL(PL_op->op_private & OPpTRANS_DELETE);
     bool inplace = ! cBOOL(PL_op->op_private & OPpTRANS_GROWS);
     const UV* from_array = invlist_array(from_invlist);
-    UV final_map;
-    bool out_is_utf8 = SvUTF8(sv);
+    UV final_map = TR_OOB;
+    bool out_is_utf8 = cBOOL(SvUTF8(sv));
     STRLEN s_len;
 
     PERL_ARGS_ASSERT_DO_TRANS_INVMAP;
@@ -416,6 +447,13 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
     }
 
     s = (U8*)SvPV_nomg(sv, len);
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: entering do_trans_invmap:"
+                                          " input sv:\n",
+                                          __FILE__, __LINE__));
+    DEBUG_y(sv_dump(sv));
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "mapping:\n"));
+    DEBUG_y(invmap_dump(from_invlist, map));
+
     send = s + len;
     s0 = s;
 
@@ -430,7 +468,7 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
          * this particular input string will grow.  However, the compilation
          * calculated the maximum expansion possible.  Use that to allocale
          * based on the worst case scenario. */
-       Newx(d, len * max_expansion + 1, U8);
+       Newx(d, (STRLEN) (len * max_expansion + 1 + 1), U8);
        d0 = d;
     }
 
@@ -464,7 +502,7 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
 
         if (to == (UV) TR_UNLISTED) { /* Just copy the unreplaced character */
             if (UVCHR_IS_INVARIANT(from) || ! out_is_utf8) {
-                *d++ = from;
+                *d++ = (U8) from;
             }
             else if (SvUTF8(sv)) {
                 Move(s, d, s_len, U8);
@@ -511,7 +549,7 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
                     matches = 0;
                     goto restart;
                 }
-                *d++ = to;
+                *d++ = (U8) to;
             }
         }
 
@@ -523,6 +561,7 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
     s += s_len;
     if (! inplace) {
        sv_setpvn(sv, (char*)d0, d - d0);
+        Safefree(d0);
     }
     else {
        *d = '\0';
@@ -534,10 +573,12 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
     }
     SvSETMAGIC(sv);
 
+    DEBUG_y(PerlIO_printf(Perl_debug_log, "%s: %d: returning %zu\n",
+                                          __FILE__, __LINE__, matches));
+    DEBUG_y(sv_dump(sv));
     return matches;
 }
 
-
 /* Execute a tr//. sv is the value to be translated, while PL_op
  * should be an OP_TRANS or OP_TRANSR op, whose op_pv field contains a
  * translation table or whose op_sv field contains an inversion map.