changeset 22724:a03e576ddfa0

lib: printf_format_fix*() - Use the same 4 digits as maximum precision length 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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 19 Oct 2017 13:26:27 +0300
parents 781ee592b295
children 878a4f623242
files src/lib/printf-format-fix.c src/lib/test-printf-format-fix.c
diffstat 2 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/printf-format-fix.c	Tue Oct 17 17:39:32 2017 +0300
+++ b/src/lib/printf-format-fix.c	Thu Oct 19 13:26:27 2017 +0300
@@ -105,11 +105,11 @@
 		/* 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);
 				}
--- a/src/lib/test-printf-format-fix.c	Tue Oct 17 17:39:32 2017 +0300
+++ b/src/lib/test-printf-format-fix.c	Thu Oct 19 13:26:27 2017 +0300
@@ -21,8 +21,8 @@
 		"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 @@
 		"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",
 	};