Typo in pp_complement().
[p5sagit/p5-mst-13.2.git] / doop.c
diff --git a/doop.c b/doop.c
index 3cdc23d..074be99 100644 (file)
--- a/doop.c
+++ b/doop.c
 #endif
 #endif
 
-#define HALF_UPGRADE(start,end) \
+#define HALF_UTF8_UPGRADE(start,end) \
     STMT_START {                               \
+      if ((start)<(end)) {                     \
        U8* NeWsTr;                             \
        STRLEN LeN = (end) - (start);           \
        NeWsTr = bytes_to_utf8(start, &LeN);    \
-       Copy(NeWsTr,start,LeN,U8*);             \
-       end = (start) + LeN;                    \
+       Safefree(start);                        \
+       (start) = NeWsTr;                       \
+       (end) = (start) + LeN;                  \
+      }                                                \
     } STMT_END
 
-
 STATIC I32
 S_do_trans_simple(pTHX_ SV *sv)
 {
@@ -91,8 +93,8 @@ S_do_trans_simple(pTHX_ SV *sv)
     }
     *d = '\0';
     sv_setpvn(sv, (const char*)dstart, d - dstart);
+    Safefree(dstart);
     SvUTF8_on(sv);
-    SvLEN_set(sv, 2*len+1);
     SvSETMAGIC(sv);
     return matches;
 }
@@ -240,16 +242,16 @@ S_do_trans_simple_utf8(pTHX_ SV *sv)/* SPC - OK */
            s += UTF8SKIP(s);
            matches++;
             if ((uv & 0x80) && !isutf++)
-                HALF_UPGRADE(dstart,d);
+                HALF_UTF8_UPGRADE(dstart,d);
            d = uv_to_utf8(d, uv);
        }
        else if (uv == none) {
            int i;
            i = UTF8SKIP(s);
             if (i > 1 && !isutf++)
-                HALF_UPGRADE(dstart,d);
+                HALF_UTF8_UPGRADE(dstart,d);
            while(i--)
-            *d++ = *s++;
+               *d++ = *s++;
        }
        else if (uv == extra) {
            int i;
@@ -257,7 +259,7 @@ S_do_trans_simple_utf8(pTHX_ SV *sv)/* SPC - OK */
            s += i;
            matches++;
             if (i > 1 && !isutf++) 
-                HALF_UPGRADE(dstart,d);
+                HALF_UTF8_UPGRADE(dstart,d);
            d = uv_to_utf8(d, final);
        }
        else
@@ -353,11 +355,11 @@ S_do_trans_complex_utf8(pTHX_ SV *sv) /* SPC - NOT OK */
                matches++;
                if (uv != puv) {
                     if ((uv & 0x80) && !isutf++) 
-                        HALF_UPGRADE(dst,d);
+                        HALF_UTF8_UPGRADE(dst,d);
                    d = uv_to_utf8(d, uv);
                    puv = uv;
                }
-                   s += UTF8SKIP(s);
+               s += UTF8SKIP(s);
                continue;
            }
            else if (uv == none) {      /* "none" is unmapped character */
@@ -485,7 +487,7 @@ Perl_do_join(pTHX_ register SV *sv, SV *del, register SV **mark, register SV **s
     (void)SvUPGRADE(sv, SVt_PV);
     if (SvLEN(sv) < len + items) {     /* current length is way too short */
        while (items-- > 0) {
-           if (*mark && !SvGMAGICAL(*mark) && SvOK(*mark)) {
+           if (*mark && !SvGAMAGIC(*mark) && SvOK(*mark)) {
                SvPV(*mark, tmplen);
                len += tmplen;
            }