Skip to content

Commit 9cc0d83

Browse files
committed
Perl_sv_vcatpvfn_flags: remove redundant code
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
1 parent 27b6e3b commit 9cc0d83

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

sv.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11862,9 +11862,6 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
1186211862
}
1186311863
#endif /* !USE_LONG_DOUBLE */
1186411864

11865-
if (!args && svix < svmax && DO_UTF8(*svargs))
11866-
has_utf8 = TRUE;
11867-
1186811865
patend = (char*)pat + patlen;
1186911866
for (p = (char*)pat; p < patend; p = q) {
1187011867

t/op/sprintf2.t

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,4 +962,14 @@ SKIP: {
962962
is($w_other, 0, "utf8 for invalid format: other warnings");
963963
}
964964

965+
# it used to upgrade the result to utf8 if the 1st arg happened to be utf8
966+
967+
{
968+
my $precis = "9";
969+
utf8::upgrade($precis);
970+
my $s = sprintf "%.*f\n", $precis, 1.1;
971+
ok(!utf8::is_utf8($s), "first arg not special utf8-wise");
972+
}
973+
974+
965975
done_testing();

0 commit comments

Comments
 (0)