This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Document NV to int cast macros
[perl5.git] / doop.c
diff --git a/doop.c b/doop.c
index 2c85c83..822ad3c 100644 (file)
--- a/doop.c
+++ b/doop.c
@@ -210,13 +210,14 @@ S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl)
                     }
                }
                else {
-                    if (this_map == (short) TR_UNMAPPED)
+                    if (this_map == (short) TR_UNMAPPED) {
                         *d++ = *s;
+                        previous_map = (short) TR_OOB;
+                    }
                     else {
                         assert(this_map == (short) TR_DELETE);
                         matches++;
                     }
-                    previous_map = (short) TR_OOB;
                 }
 
                s++;
@@ -288,6 +289,7 @@ S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl)
             else if (sch == (short) TR_UNMAPPED) {
                 Move(s, d, len, U8);
                 d += len;
+                pch = TR_OOB;
             }
             else if (sch == (short) TR_DELETE)
                 matches++;
@@ -298,7 +300,6 @@ S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl)
             }
 
             s += len;
-            pch = TR_OOB;
         }
 
        if (grows) {
@@ -441,9 +442,6 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
      * assume cannot */
     if (! out_is_utf8 && (PL_op->op_private & OPpTRANS_CAN_FORCE_UTF8)) {
         inplace = FALSE;
-        if (max_expansion < 2) {
-            max_expansion = 2;
-        }
     }
 
     s = (U8*)SvPV_nomg(sv, len);
@@ -466,8 +464,9 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
     else {
         /* Here, we can't edit in place.  We have no idea how much, if any,
          * this particular input string will grow.  However, the compilation
-         * calculated the maximum expansion possible.  Use that to allocale
-         * based on the worst case scenario. */
+         * calculated the maximum expansion possible.  Use that to allocate
+         * based on the worst case scenario.  (First +1 is to round up; 2nd is
+         * for \0) */
        Newx(d, (STRLEN) (len * max_expansion + 1 + 1), U8);
        d0 = d;
     }
@@ -522,7 +521,6 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
 
         if (to == (UV) TR_SPECIAL_HANDLING) {
             if (delete_unfound) {
-                previous_map = to;
                 s += s_len;
                 continue;
             }
@@ -730,7 +728,6 @@ Perl_do_sprintf(pTHX_ SV *sv, SSize_t len, SV **sarg)
        SvTAINTED_on(sv);
 }
 
-/* currently converts input to bytes if possible, but doesn't sweat failure */
 UV
 Perl_do_vecget(pTHX_ SV *sv, STRLEN offset, int size)
 {
@@ -756,7 +753,8 @@ Perl_do_vecget(pTHX_ SV *sv, STRLEN offset, int size)
             s = (unsigned char *) SvPV_flags(sv, srclen, svpv_flags);
         }
         else {
-               Perl_croak(aTHX_ "Use of strings with code points over 0xFF as arguments to vec is forbidden");
+            Perl_croak(aTHX_ "Use of strings with code points over 0xFF"
+                             " as arguments to vec is forbidden");
         }
     }
 
@@ -856,7 +854,7 @@ Perl_do_vecget(pTHX_ SV *sv, STRLEN offset, int size)
        }
     }
     else if (size < 8)
-       retnum = (s[uoffset] >> bitoffs) & ((1 << size) - 1);
+       retnum = (s[uoffset] >> bitoffs) & nBIT_MASK(size);
     else {
        if (size == 8)
            retnum = s[uoffset];
@@ -959,7 +957,7 @@ Perl_do_vecset(pTHX_ SV *sv)
     }
 
     if (size < 8) {
-       mask = (1 << size) - 1;
+       mask = nBIT_MASK(size);
        lval &= mask;
        s[offset] &= ~(mask << bitoffs);
        s[offset] |= lval << bitoffs;
@@ -1089,7 +1087,6 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
     lsave = lc;
     rsave = rc;
 
-    SvCUR_set(sv, len);
     (void)SvPOK_only(sv);
     if (SvOK(sv) || SvTYPE(sv) > SVt_PVMG) {
        dc = SvPV_force_nomg_nolen(sv);
@@ -1105,6 +1102,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
        sv_usepvn_flags(sv, dc, needlen, SV_HAS_TRAILING_NUL);
        dc = SvPVX(sv);         /* sv_usepvn() calls Renew() */
     }
+    SvCUR_set(sv, len);
 
     if (len >= sizeof(long)*4 &&
        !(PTR2nat(dc) % sizeof(long)) &&