Mercurial > dovecot > core-2.2
changeset 22726:dcec0ced2c50
lib: printf_format_fix*() - Support '*' in precision
We're commonly using "%.*s"
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 19 Oct 2017 13:05:41 +0300 |
parents | 878a4f623242 |
children | 37d5a5c7a7b7 |
files | src/lib/printf-format-fix.c src/lib/test-printf-format-fix.c |
diffstat | 2 files changed, 5 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/printf-format-fix.c Thu Oct 19 13:02:34 2017 +0300 +++ b/src/lib/printf-format-fix.c Thu Oct 19 13:05:41 2017 +0300 @@ -111,16 +111,10 @@ /* 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); } }
--- a/src/lib/test-printf-format-fix.c Thu Oct 19 13:02:34 2017 +0300 +++ b/src/lib/test-printf-format-fix.c Thu Oct 19 13:05:41 2017 +0300 @@ -21,8 +21,10 @@ "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 @@ "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)) {