diff options
author | Hugo van der Sanden <hv@crypt.org> | 2019-04-09 14:27:41 +0100 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2019-10-21 12:42:04 +0100 |
commit | 1a5b2aa2d038f54a0d983a6c77fd942dc24f0bf4 (patch) | |
tree | eab7c6976e74e2d2cee1a1f563d8b9fcdf7563be | |
parent | a39fd5ac91237118c4b6ca00a2da2970f6689cd6 (diff) | |
download | perl-1a5b2aa2d038f54a0d983a6c77fd942dc24f0bf4.tar.gz |
[#134008] More carefully ignore negative precision in sprintf
Check has_precis more consistently; ensure precis is left as 0 if provided
as a negative number.
(cherry picked from commit b0f5b1daacb21ab7e46a772a6ff0f70ca627cb58)
-rw-r--r-- | sv.c | 7 | ||||
-rw-r--r-- | t/op/sprintf2.t | 3 |
2 files changed, 8 insertions, 2 deletions
@@ -11763,11 +11763,11 @@ S_format_hexfp(pTHX_ char * const buf, const STRLEN bufsize, const char c, else { *p++ = '0'; exponent = 0; - zerotail = precis; + zerotail = has_precis ? precis : 0; } /* The radix is always output if precis, or if alt. */ - if (precis > 0 || alt) { + if ((has_precis && precis > 0) || alt) { hexradix = TRUE; } @@ -12221,6 +12221,9 @@ Perl_sv_vcatpvfn_flags(pTHX_ SV *const sv, const char *const pat, const STRLEN p } precis = S_sprintf_arg_num_val(aTHX_ args, i, sv, &neg); has_precis = !neg; + /* ignore negative precision */ + if (!has_precis) + precis = 0; } } else { diff --git a/t/op/sprintf2.t b/t/op/sprintf2.t index dc87821152..569bd8053d 100644 --- a/t/op/sprintf2.t +++ b/t/op/sprintf2.t @@ -838,6 +838,9 @@ SKIP: { # [rt.perl.org #128889] is(sprintf("%.*a", -1, 1.03125), "0x1.08p+0", "[rt.perl.org #128889]"); + # [rt.perl.org #134008] + is(sprintf("%.*a", -99999, 1.03125), "0x1.08p+0", "[rt.perl.org #134008]"); + # [rt.perl.org #128890] is(sprintf("%a", 0x1.18p+0), "0x1.18p+0"); is(sprintf("%.1a", 0x1.08p+0), "0x1.0p+0"); |