Skip to content

Commit

Permalink
[rt.perl.org #128888]: printf %a mishandles zero precision
Browse files Browse the repository at this point in the history
  • Loading branch information
jhi committed Aug 11, 2016
1 parent 520f3e5 commit 82229f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion t/op/sprintf2.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]");

0 comments on commit 82229f9

Please sign in to comment.