This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[rt.perl.org #128888]: printf %a mishandles zero precision
authorJarkko Hietaniemi <jhi@iki.fi>
Wed, 10 Aug 2016 23:06:03 +0000 (19:06 -0400)
committerJarkko Hietaniemi <jhi@iki.fi>
Thu, 11 Aug 2016 13:36:21 +0000 (09:36 -0400)
sv.c
t/op/sprintf2.t

diff --git a/sv.c b/sv.c
index 93e6364..ac41af2 100644 (file)
--- a/sv.c
+++ b/sv.c
@@ -12510,7 +12510,7 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p
                       v0 = vhex;
                     }
 
-                    if (precis > 0) {
+                    if (has_precis) {
                         U8* ve = (subnormal ? vlnz + 1 : vend);
                         SSize_t vn = ve - (subnormal ? vfnz : vhex);
                         if ((SSize_t)(precis + 1) < vn) {
index f53dd83..0f99fd3 100644 (file)
@@ -262,7 +262,7 @@ if ($Config{nvsize} == 8 &&
     print "# no hexfloat tests\n";
 }
 
-plan tests => 1408 + ($Q ? 0 : 12) + @hexfloat + 37;
+plan tests => 1408 + ($Q ? 0 : 12) + @hexfloat + 40;
 
 use strict;
 use Config;
@@ -802,3 +802,8 @@ SKIP: {
         is($s, $t->[2], "subnormal @$t got $s");
     }
 }
+
+# [rt.perl.org #128888]
+is(sprintf("%a", 1.03125),   "0x1.08p+0");
+is(sprintf("%.1a", 1.03125), "0x1.0p+0");
+is(sprintf("%.0a", 1.03125), "0x1p+0", "[rt.perl.org #128888]");