From: Vsevolod Stakhov Date: Sat, 6 Apr 2019 11:25:43 +0000 (+0100) Subject: [Minor] Oops, forgot to adpot long double case X-Git-Tag: 1.9.2~68 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=aa47bd08154dd05c9e0c4d40c31c8488560885e7;p=rspamd.git [Minor] Oops, forgot to adpot long double case --- 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; } }