From: Vsevolod Stakhov Date: Tue, 10 Jul 2018 11:56:55 +0000 (+0100) Subject: [Fix] Fix padded numbers printing X-Git-Tag: 1.7.8~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3f3e6a3ebf7137a632e5cfa71421c3eb5898c638;p=rspamd.git [Fix] Fix padded numbers printing --- diff --git a/src/libutil/printf.c b/src/libutil/printf.c index 0ad2dce27..be4ef402e 100644 --- a/src/libutil/printf.c +++ b/src/libutil/printf.c @@ -371,7 +371,7 @@ rspamd_sprintf_num (gchar *buf, gchar *last, guint64 ui64, gchar zero, *--p = _hex[(guint32) (ui64 & 0xf)]; } while (ui64 >>= 4); - len = (temp + sizeof (temp)) - p + 1; + len = (temp + sizeof (temp)) - p; } else { /* hexadecimal == 2 */ p = temp + sizeof(temp); @@ -379,13 +379,17 @@ rspamd_sprintf_num (gchar *buf, gchar *last, guint64 ui64, gchar zero, *--p = _HEX[(guint32) (ui64 & 0xf)]; } while (ui64 >>= 4); - len = (temp + sizeof (temp)) - p + 1; + len = (temp + sizeof (temp)) - p; } /* zero or space padding */ - while (width > 0 && buf < last) { - *buf++ = zero; + if (len < width) { + width -= len; + + while (width-- > 0 && buf < last) { + *buf++ = zero; + } } /* number safe copy */