Make scan_num() reëntrant, as suggested in
[p5sagit/p5-mst-13.2.git] / pp.c
diff --git a/pp.c b/pp.c
index 84949aa..98d31cb 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -1468,53 +1468,53 @@ PP(pp_complement)
        }
       }
       else {
-       register char *tmps;
-       register long *tmpl;
+       register U8 *tmps;
        register I32 anum;
        STRLEN len;
 
        SvSetSV(TARG, sv);
-       tmps = SvPV_force(TARG, len);
+       tmps = (U8*)SvPV_force(TARG, len);
        anum = len;
        if (SvUTF8(TARG)) {
          /* Calculate exact length, let's not estimate */
          STRLEN targlen = 0;
          U8 *result;
-         char *send;
+         U8 *send;
+         I32 l;
 
          send = tmps + len;
          while (tmps < send) {
-           I32 l;
            UV c = utf8_to_uv(tmps, &l);
-           c = (UV)~c;
            tmps += UTF8SKIP(tmps);
-           targlen += UTF8LEN(c);
+           targlen += UTF8LEN(~c);
          }
 
          /* Now rewind strings and write them. */
          tmps -= len;
          Newz(0, result, targlen + 1, U8);
          while (tmps < send) {
-           I32 l;
            UV c = utf8_to_uv(tmps, &l);
            tmps += UTF8SKIP(tmps);
            result = uv_to_utf8(result,(UV)~c);
          }
          *result = '\0';
          result -= targlen;
-         sv_setpvn(TARG, result, targlen);
+         sv_setpvn(TARG, (char*)result, targlen);
          SvUTF8_on(TARG);
          Safefree(result);
          SETs(TARG);
          RETURN;
        }
 #ifdef LIBERAL
-       for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++)
-           *tmps = ~*tmps;
-       tmpl = (long*)tmps;
-       for ( ; anum >= sizeof(long); anum -= sizeof(long), tmpl++)
-           *tmpl = ~*tmpl;
-       tmps = (char*)tmpl;
+       {
+           register long *tmpl;
+           for ( ; anum && (unsigned long)tmps % sizeof(long); anum--, tmps++)
+               *tmps = ~*tmps;
+           tmpl = (long*)tmps;
+           for ( ; anum >= sizeof(long); anum -= sizeof(long), tmpl++)
+               *tmpl = ~*tmpl;
+           tmps = (U8*)tmpl;
+       }
 #endif
        for ( ; anum > 0; anum--, tmps++)
            *tmps = ~*tmps;
@@ -1889,11 +1889,24 @@ PP(pp_int)
        SETi(iv);
       }
       else {
-       if (value >= 0.0)
-         (void)Perl_modf(value, &value);
+         if (value >= 0.0) {
+#if defined(HAS_MODFL) || defined(LONG_DOUBLE_EQUALS_DOUBLE)
+             (void)Perl_modf(value, &value);
+#else
+             double tmp = (double)value;
+             (void)Perl_modf(tmp, &tmp);
+             value = (NV)tmp;
+#endif
+         }
        else {
-         (void)Perl_modf(-value, &value);
-         value = -value;
+#if defined(HAS_MODFL) || defined(LONG_DOUBLE_EQUALS_DOUBLE)
+           (void)Perl_modf(-value, &value);
+           value = -value;
+#else
+           double tmp = (double)value;
+           (void)Perl_modf(-tmp, &tmp);
+           value = -(NV)tmp;
+#endif
        }
        iv = I_V(value);
        if (iv == value)