This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp_formline: no need to *t = '\0' until end
[perl5.git] / pp_ctl.c
index 7b037da..acab077 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -609,7 +609,6 @@ PP(pp_formline)
            if (targ_is_utf8 && !item_is_utf8) {
                char *s;
                SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
-               *t = '\0';
 
                /* this is an unrolled sv_catpvn_utf8_upgrade(),
                 * but with the addition of s/~/ /g */
@@ -630,7 +629,6 @@ PP(pp_formline)
            }
            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, 0, fudge + 1);
                t = SvEND(PL_formtarget);
                targ_is_utf8 = TRUE;
@@ -816,7 +814,6 @@ PP(pp_formline)
                if (item_is_utf8) {
                    if (!targ_is_utf8) {
                        SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
-                       *t = '\0';
                        sv_utf8_upgrade_flags_grow(PL_formtarget, 0,
                                                                    fudge + 1);
                        t = SvEND(PL_formtarget);
@@ -849,7 +846,6 @@ PP(pp_formline)
                }
                if (targ_is_utf8 && !item_is_utf8) {
                    SvCUR_set(PL_formtarget, t - SvPVX_const(PL_formtarget));
-                   *t = '\0';
                    sv_catpvn_utf8_upgrade(PL_formtarget, s, arg, nsv);
                    for (; t < SvEND(PL_formtarget); t++) {
 #ifdef EBCDIC
@@ -919,24 +915,20 @@ PP(pp_formline)
 
            {
                U8 *tmp = NULL;
+
+               SvCUR_set(PL_formtarget,
+                         t - SvPVX_const(PL_formtarget));
+
                if (targ_is_utf8 && !item_is_utf8) {
                    source = tmp = bytes_to_utf8(source, &to_copy);
-                   SvCUR_set(PL_formtarget,
-                             t - SvPVX_const(PL_formtarget));
                } else {
                    if (item_is_utf8 && !targ_is_utf8) {
                        /* Upgrade targ to UTF8, and then we reduce it to
-                          a problem we have a simple solution for.  */
-                       SvCUR_set(PL_formtarget,
-                                 t - SvPVX_const(PL_formtarget));
-                       targ_is_utf8 = TRUE;
-                       /* Don't need get magic.  */
+                          a problem we have a simple solution for.
+                          Don't need get magic.  */
                        sv_utf8_upgrade_nomg(PL_formtarget);
-                   } else {
-                       SvCUR_set(PL_formtarget,
-                                 t - SvPVX_const(PL_formtarget));
+                       targ_is_utf8 = TRUE;
                    }
-
                    /* Easy. They agree.  */
                    assert (item_is_utf8 == targ_is_utf8);
                }