This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_formline: don't set itemsize in FF_LINEGLOB
[perl5.git] / pp_ctl.c
index 3304eac..7b037da 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -605,7 +605,8 @@ PP(pp_formline)
 
        case FF_LITERAL:
            arg = *fpc++;
-           if (targ_is_utf8 && !SvUTF8(formsv)) {
+           item_is_utf8 = targ_is_utf8 ? !!DO_UTF8(formsv) : !!SvUTF8(formsv);
+           if (targ_is_utf8 && !item_is_utf8) {
                char *s;
                SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
                *t = '\0';
@@ -627,10 +628,10 @@ PP(pp_formline)
                f += arg;
                break;
            }
-           if (!targ_is_utf8 && DO_UTF8(formsv)) {
+           if (!targ_is_utf8 && item_is_utf8) {
                SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
                *t = '\0';
-               sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC, fudge + 1);
+               sv_utf8_upgrade_flags_grow(PL_formtarget, 0, fudge + 1);
                t = SvEND(PL_formtarget);
                targ_is_utf8 = TRUE;
            }
@@ -816,7 +817,7 @@ PP(pp_formline)
                    if (!targ_is_utf8) {
                        SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
                        *t = '\0';
-                       sv_utf8_upgrade_flags_grow(PL_formtarget, SV_GMAGIC,
+                       sv_utf8_upgrade_flags_grow(PL_formtarget, 0,
                                                                    fudge + 1);
                        t = SvEND(PL_formtarget);
                        targ_is_utf8 = TRUE;
@@ -892,14 +893,12 @@ PP(pp_formline)
                const bool oneline = fpc[-1] == FF_LINESNGL;
                const char *s = item = SvPV_const(sv, len);
                const char *const send = s + len;
-               U8 *tmp = NULL;
 
                item_is_utf8 = DO_UTF8(sv);
-               itemsize = len;
-               if (!itemsize)
+               if (!len)
                    break;
                gotsome = TRUE;
-               chophere = s + itemsize;
+               chophere = s + len;
                source = (U8 *) s;
                to_copy = len;
                while (s < send) {
@@ -910,13 +909,16 @@ PP(pp_formline)
                            break;
                        } else {
                            if (s == send) {
-                               itemsize--;
                                to_copy--;
                            } else
                                lines++;
                        }
                    }
                }
+           }
+
+           {
+               U8 *tmp = NULL;
                if (targ_is_utf8 && !item_is_utf8) {
                    source = tmp = bytes_to_utf8(source, &to_copy);
                    SvCUR_set(PL_formtarget,
@@ -945,19 +947,8 @@ PP(pp_formline)
                Copy(source, t, to_copy, char);
                t += to_copy;
                SvCUR_set(PL_formtarget, SvCUR(PL_formtarget) + to_copy);
-               if (item_is_utf8) {
-                   if (SvGMAGICAL(sv)) {
-                       /* Mustn't call sv_pos_b2u() as it does a second
-                          mg_get(). Is this a bug? Do we need a _flags()
-                          variant? */
-                       itemsize = utf8_length(source, source + itemsize);
-                   } else {
-                       sv_pos_b2u(sv, &itemsize);
-                   }
-                   assert(!tmp);
-               } else if (tmp) {
+               if (tmp)
                    Safefree(tmp);
-               }
                break;
            }