]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: printf_format_fix*() - Use the same 4 digits as maximum precision length
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 19 Oct 2017 10:26:27 +0000 (13:26 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Thu, 19 Oct 2017 15:13:07 +0000 (18:13 +0300)
I forgot the precision can also be used to truncate strings, not just
specify the precision for floating point numbers. So it makes more sense
that the limit is the same as for minimum field width.

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

index 3e863105cbd1772f4fa2ba42e24137c4c9184a93..ac9443d75ed2332e3f58d55ef27357d013b0edaa 100644 (file)
@@ -105,11 +105,11 @@ 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. 999 should be long enough precision. */
+                          here. 9999 should be long enough precision. */
                        unsigned int i = 0;
                        p++;
                        while (*p >= '0' && *p <= '9') {
-                               if (++i > 3) {
+                               if (++i > 4) {
                                        i_panic("Too large precision starting at #%u in '%s'",
                                                start_pos, format);
                                }
index 0e9b8caab6353cdb2776b3268723221f6323f02d..9409ea59ee9c07017330fd14748a03887a8bceaf 100644 (file)
@@ -21,8 +21,8 @@ static void test_unchanged()
                "Allow %#0- +s flags",
                "duplicate flags in different args %0-123s %0-123s",
                "Minimum length %9999s",
-               "Precision %.999s",
-               "Precision %1.999s",
+               "Precision %.9999s",
+               "Precision %1.9999s",
                "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",
@@ -116,8 +116,8 @@ enum fatal_test_state fatal_printf_format_fix(unsigned int stage)
                "No duplicate modifiers %00s",
                "Minimum length can't be too long %10000s",
                "Minimum length doesn't support %*1$s",
-               "Precision can't be too long %.1000s",
-               "Precision can't be too long %1.1000s",
+               "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",
        };