commit aa47bd0: [Minor] Oops, forgot to adpot long double case

Vsevolod Stakhov vsevolod at highsecure.ru
Sat Apr 6 11:28:27 UTC 2019


Author: Vsevolod Stakhov
Date: 2019-04-06 12:25:43 +0100
URL: https://github.com/rspamd/rspamd/commit/aa47bd08154dd05c9e0c4d40c31c8488560885e7 (HEAD -> master)

[Minor] Oops, forgot to adpot long double case

---
 src/libutil/printf.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 403fa8877..9dc14441c 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -988,9 +988,25 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
 				if (frac_width != 0) {
 					const gchar *dot_pos = memchr (dtoabuf, '.', slen);
 
-					if (dot_pos && frac_width < (slen - ((dot_pos - dtoabuf) + 1))) {
-						slen = (dot_pos - dtoabuf) + 1 + /* xxx. */
-								frac_width; /* .yyy */
+					if (dot_pos) {
+						if (frac_width < (slen - ((dot_pos - dtoabuf) + 1))) {
+							/* Truncate */
+							slen = (dot_pos - dtoabuf) + 1 + /* xxx. */
+								   frac_width; /* .yyy */
+						}
+						else if (frac_width + dot_pos + 1 < dtoabuf + sizeof (dtoabuf)) {
+							/* Expand */
+							frac_width -= slen - ((dot_pos - dtoabuf) + 1);
+							memset (dtoabuf + slen, '0', frac_width);
+							slen += frac_width;
+						}
+					}
+					else {
+						/* Expand */
+						frac_width = MIN (frac_width, sizeof (dtoabuf) - slen - 1);
+						dtoabuf[slen ++] = '.';
+						memset (dtoabuf + slen, '0', frac_width);
+						slen += frac_width;
 					}
 				}
 


More information about the Commits mailing list