aboutsummaryrefslogtreecommitdiffstats
path: root/src/libutil/printf.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-10 18:31:00 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-12-10 18:31:00 +0000
commitfe8a77e7d13abe5134ad0751e628d73d872b7d45 (patch)
treeccda4847cbe10fdda953acc5b0d215fd1087721c /src/libutil/printf.c
parenta3d47650a1b1a9ab15a779bc6ed35e06850ac2b5 (diff)
downloadrspamd-fe8a77e7d13abe5134ad0751e628d73d872b7d45.tar.gz
rspamd-fe8a77e7d13abe5134ad0751e628d73d872b7d45.zip
Add support of width modifier for strings in printf
Diffstat (limited to 'src/libutil/printf.c')
-rw-r--r--src/libutil/printf.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 11143f79f..a6099f83f 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -482,8 +482,14 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
case 'V':
v = va_arg (args, rspamd_fstring_t *);
+ slen = v->len;
+
+ if (G_UNLIKELY (width != 0)) {
+ slen = MIN (v->len, width);
+ }
+
if (v) {
- RSPAMD_PRINTF_APPEND (v->str, v->len);
+ RSPAMD_PRINTF_APPEND (v->str, slen);
}
else {
RSPAMD_PRINTF_APPEND ("(NULL)", 6);
@@ -493,8 +499,14 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
case 'T':
tok = va_arg (args, rspamd_ftok_t *);
+ slen = tok->len;
+
+ if (G_UNLIKELY (width != 0)) {
+ slen = MIN (tok->len, width);
+ }
+
if (tok) {
- RSPAMD_PRINTF_APPEND (tok->begin, tok->len);
+ RSPAMD_PRINTF_APPEND (tok->begin, slen);
}
else {
RSPAMD_PRINTF_APPEND ("(NULL)", 6);
@@ -503,8 +515,13 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
case 'v':
gs = va_arg (args, GString *);
+ slen = gs->len;
+
+ if (G_UNLIKELY (width != 0)) {
+ slen = MIN (gs->len, width);
+ }
if (gs) {
- RSPAMD_PRINTF_APPEND (gs->str, gs->len);
+ RSPAMD_PRINTF_APPEND (gs->str, slen);
}
else {
RSPAMD_PRINTF_APPEND ("(NULL)", 6);
@@ -542,6 +559,10 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
slen = strlen (p);
}
+ if (G_UNLIKELY (width != 0)) {
+ slen = MIN (slen, width);
+ }
+
if (G_LIKELY(hex == 0)) {
RSPAMD_PRINTF_APPEND (p, slen);
}