]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib/printf-format-fix: fix rejection of "%.0f" as a valid string
authorPhil Carmody <phil@dovecot.fi>
Wed, 3 Jan 2018 13:54:15 +0000 (15:54 +0200)
committerMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Fri, 21 Sep 2018 10:30:25 +0000 (13:30 +0300)
Sometimes you want to calculate in floats, but don't want the decimals
printed.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/printf-format-fix.c
src/lib/test-printf-format-fix.c

index 69539875c392e40e2110760b91d3fad9a6ef0024..001e7b02f73b3f9eefc9cceeefd4e40de99ec7e7 100644 (file)
@@ -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;
index d369cf7f69ca296cc9e2bdd3d1e3704cca51ee6b..c9d6203de30bb7c5081957eac4916e404786d070 100644 (file)
@@ -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",