aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/printf.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-10 12:56:55 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-07-10 12:56:55 +0100
commit3f3e6a3ebf7137a632e5cfa71421c3eb5898c638 (patch)
treeb86e4ecb95a134e9a21a7a982d9e1136b7d54b93 /src/libutil/printf.c
parenta444ae89b582c59aea1255f9fdf07e822f78bf26 (diff)
downloadrspamd-3f3e6a3ebf7137a632e5cfa71421c3eb5898c638.tar.gz
rspamd-3f3e6a3ebf7137a632e5cfa71421c3eb5898c638.zip
[Fix] Fix padded numbers printing
Diffstat (limited to 'src/libutil/printf.c')
-rw-r--r--src/libutil/printf.c12
1 files changed, 8 insertions, 4 deletions
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 */