From aa47bd08154dd05c9e0c4d40c31c8488560885e7 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sat, 6 Apr 2019 12:25:43 +0100 Subject: [PATCH] [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; } } -- 2.39.5