A bug introduced in #8217 (the undefined variable in the
[p5sagit/p5-mst-13.2.git] / sv.c
diff --git a/sv.c b/sv.c
index 526ed08..93188df 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -2957,6 +2957,7 @@ Perl_sv_utf8_upgrade(pTHX_ register SV *sv)
 
     if (hibit) {
        STRLEN len;
+
        if (SvREADONLY(sv) && SvFAKE(sv)) {
            sv_force_normal(sv);
            s = SvPVX(sv);
@@ -2987,10 +2988,13 @@ Perl_sv_utf8_downgrade(pTHX_ register SV* sv, bool fail_ok)
 {
     if (SvPOK(sv) && SvUTF8(sv)) {
         if (SvCUR(sv)) {
-           char *c = SvPVX(sv);
-           STRLEN len = SvCUR(sv);
+           char *s;
+           STRLEN len;
 
-           if (!utf8_to_bytes((U8*)c, &len)) {
+           if (SvREADONLY(sv) && SvFAKE(sv))
+               sv_force_normal(sv);
+           s = SvPV(sv, len);
+           if (!utf8_to_bytes((U8*)s, &len)) {
                if (fail_ok)
                    return FALSE;
                else {
@@ -6705,7 +6709,7 @@ Perl_sv_vsetpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
 }
 
 I32
-S_expect_number(char** pattern)
+S_expect_number(pTHX_ char** pattern)
 {
     I32 var = 0;
     switch (**pattern) {
@@ -6717,7 +6721,7 @@ S_expect_number(char** pattern)
     }
     return var;
 }
-#define EXPECT_NUMBER(pattern, var) (var = S_expect_number(&pattern))
+#define EXPECT_NUMBER(pattern, var) (var = S_expect_number(aTHX_ &pattern))
 
 /*
 =for apidoc sv_vcatpvfn
@@ -6780,7 +6784,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
        bool left = FALSE;
        bool vectorize = FALSE;
        bool vectorarg = FALSE;
-       bool utf = FALSE;
+       bool vec_utf = FALSE;
        char fill = ' ';
        char plus = 0;
        char intsize = 0;
@@ -6911,26 +6915,24 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
                else
                    vecsv = (evix ? evix <= svmax : svix < svmax) ?
                        svargs[ewix ? ewix-1 : svix++] : &PL_sv_undef;
-               dotstr = (U8*)SvPVx(vecsv, dotstrlen);
+               dotstr = SvPVx(vecsv, dotstrlen);
                if (DO_UTF8(vecsv))
                    is_utf = TRUE;
            }
            if (args) {
                vecsv = va_arg(*args, SV*);
                vecstr = (U8*)SvPVx(vecsv,veclen);
-               utf = DO_UTF8(vecsv);
+               vec_utf = DO_UTF8(vecsv);
            }
            else if (efix ? efix <= svmax : svix < svmax) {
                vecsv = svargs[efix ? efix-1 : svix++];
                vecstr = (U8*)SvPVx(vecsv,veclen);
-               utf = DO_UTF8(vecsv);
+               vec_utf = DO_UTF8(vecsv);
            }
            else {
                vecstr = (U8*)"";
                veclen = 0;
            }
-           if (DO_UTF8(vecsv))
-               is_utf = TRUE;
        }
 
        if (asterisk) {
@@ -7099,7 +7101,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
                STRLEN ulen;
                if (!veclen)
                    continue;
-               if (utf)
+               if (vec_utf)
                    iv = (IV)utf8_to_uv(vecstr, veclen, &ulen, 0);
                else {
                    iv = *vecstr;
@@ -7179,7 +7181,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
        vector:
                if (!veclen)
                    continue;
-               if (utf)
+               if (vec_utf)
                    uv = utf8_to_uv(vecstr, veclen, &ulen, 0);
                else {
                    uv = *vecstr;
@@ -7369,7 +7371,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
 #endif
                }
            }
-           else 
+           else
                sv_setuv_mg(argsv, (UV)i);
            continue;   /* not "break" */
 
@@ -7405,7 +7407,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
            /* ... right here, because formatting flags should not apply */
            SvGROW(sv, SvCUR(sv) + elen + 1);
            p = SvEND(sv);
-           memcpy(p, eptr, elen);
+           Copy(eptr, p, elen, char);
            p += elen;
            *p = '\0';
            SvCUR(sv) = p - SvPVX(sv);
@@ -7435,7 +7437,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
                *p++ = '0';
        }
        if (elen) {
-           memcpy(p, eptr, elen);
+           Copy(eptr, p, elen, char);
            p += elen;
        }
        if (gap && left) {
@@ -7444,7 +7446,7 @@ Perl_sv_vcatpvfn(pTHX_ SV *sv, const char *pat, STRLEN patlen, va_list *args, SV
        }
        if (vectorize) {
            if (veclen) {
-               memcpy(p, dotstr, dotstrlen);
+               Copy(dotstr, p, dotstrlen, char);
                p += dotstrlen;
            }
            else
@@ -8878,7 +8880,7 @@ perl_clone_using(PerlInterpreter *proto_perl, UV flags,
 
     if (proto_perl->Ipsig_pend) {
        Newz(0, PL_psig_pend, SIG_SIZE, int);
-    } 
+    }
     else {
        PL_psig_pend    = (int*)NULL;
     }