Skip to content

Commit

Permalink
lib/printf-format-fix: fix rejection of "%.0f" as a valid string
Browse files Browse the repository at this point in the history
Sometimes you want to calculate in floats, but don't want the decimals
printed.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
  • Loading branch information
Phil Carmody committed Jan 3, 2018
1 parent a4ec27b commit 9bf221d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib/printf-format-fix.c
Expand Up @@ -38,11 +38,12 @@ static bool verify_length(const char **p)
/* We don't bother supporting "*m$" - it's not used
anywhere and seems a bit dangerous. */
*p += 1;
} else if (**p >= '1' && **p <= '9') {
} else if (**p >= '0' && **p <= '9') {
/* Limit to 4 digits - we'll never want more than that.
Some implementations might not handle long digits
correctly, or maybe even could be used for DoS due
to using too much CPU. */
to using too much CPU. If you want to express '99'
as '00099', then you lose in this function. */
unsigned int i = 0;
do {
*p += 1;
Expand Down
1 change: 1 addition & 0 deletions src/lib/test-printf-format-fix.c
Expand Up @@ -25,6 +25,7 @@ static void test_unchanged()
"Precision %.9999s",
"Precision %1.9999s",
"Precision parameter %1.*s %.*s",
"Floating precisions such as %.0f %0.4f %-4.0f",
"Length modifiers %hd %hhd %ld %lld %Lg %jd %zd %td",
"Specifiers %s %u %d %c %i %x %X %p %o %e %E %f %F %g %G %a %A",
"%%doesn't cause confusion in %%m and %%n",
Expand Down

0 comments on commit 9bf221d

Please sign in to comment.