This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Perl_sv_vcatpvfn_flags: remove redundant code
authorDavid Mitchell <davem@iabyn.com>
Sat, 20 May 2017 12:01:02 +0000 (13:01 +0100)
committerDavid Mitchell <davem@iabyn.com>
Wed, 7 Jun 2017 08:11:03 +0000 (09:11 +0100)
At the start of the function, it marks the output as being utf8 if the
first arg is utf8. But this should be taken care of when the individual
args (including the first one are processed). So its redundant code.

In fact it would sometimes cause the resultant string to be unnecessarily
upgraded to utf8, e.g.:

    my $precis = "9";
    utf8::upgrade($precis);
    my $s = sprintf "%.*f\n", $precis, 1.1;
    # whoops, $s is now utf8

sv.c
t/op/sprintf2.t

diff --git a/sv.c b/sv.c
index 0520ac0..32e0346 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -11862,9 +11862,6 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
     }
 #endif /* !USE_LONG_DOUBLE */
 
-    if (!args && svix < svmax && DO_UTF8(*svargs))
-       has_utf8 = TRUE;
-
     patend = (char*)pat + patlen;
     for (p = (char*)pat; p < patend; p = q) {
 
index 3919c12..adbcc7b 100644 (file)
@@ -962,4 +962,14 @@ SKIP: {
     is($w_other, 0, "utf8 for invalid format: other warnings");
 }
 
+# it used to upgrade the result to utf8 if the 1st arg happened to be utf8
+
+{
+    my $precis = "9";
+    utf8::upgrade($precis);
+    my $s = sprintf "%.*f\n", $precis, 1.1;
+    ok(!utf8::is_utf8($s), "first arg not special utf8-wise");
+}
+
+
 done_testing();