]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: printf_format_fix*() - Support '*' in precision
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 19 Oct 2017 10:05:41 +0000 (13:05 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Wed, 3 Jan 2018 14:09:44 +0000 (16:09 +0200)
We're commonly using "%.*s"

src/lib/printf-format-fix.c
src/lib/test-printf-format-fix.c

index bea65b1759a89dddf8d08fdde29b48c162d89eaf..69539875c392e40e2110760b91d3fad9a6ef0024 100644 (file)
@@ -111,16 +111,10 @@ printf_format_fix_noalloc(const char *format, size_t *len_r)
 
                /* 3) Optional precision */
                if (*p == '.') {
-                       /* We don't bother supporting anything but numbers
-                          here. 9999 should be long enough precision. */
-                       unsigned int i = 0;
                        p++;
-                       while (*p >= '0' && *p <= '9') {
-                               if (++i > 4) {
-                                       i_panic("Too large precision starting at #%u in '%s'",
-                                               start_pos, format);
-                               }
-                               p++;
+                       if (!verify_length(&p)) {
+                               i_panic("Too large precision starting at #%u in '%s'",
+                                       start_pos, format);
                        }
                }
 
index 6c01541792f5df12588fdada373a59a3f60faf6f..85f9b7a03cb1f77050bddfd29eeebc3862e49fd6 100644 (file)
@@ -21,8 +21,10 @@ static void test_unchanged()
                "Allow %#0- +s flags",
                "duplicate flags in different args %0-123s %0-123s",
                "Minimum length %9999s",
+               "Minimum length parameter %*s",
                "Precision %.9999s",
                "Precision %1.9999s",
+               "Precision parameter %1.*s %.*s",
                "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",
@@ -119,7 +121,6 @@ enum fatal_test_state fatal_printf_format_fix(unsigned int stage)
                "Precision can't be too long %.10000s",
                "Precision can't be too long %1.10000s",
                "Precision doesn't support %1.-1s",
-               "Precision doesn't support %1.*s",
        };
 
        if(stage >= N_ELEMENTS(fatals)) {