]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Oops, forgot to adpot long double case
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Apr 2019 11:25:43 +0000 (12:25 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Sat, 6 Apr 2019 11:25:43 +0000 (12:25 +0100)
src/libutil/printf.c

index 403fa88772f51aa519c23fc0e1297ab6b57d2538..9dc14441cf01c364cf31553d5a5e36ccffa67d1e 100644 (file)
@@ -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;
                                        }
                                }