From: Vsevolod Stakhov Date: Thu, 10 Dec 2015 18:31:00 +0000 (+0000) Subject: Add support of width modifier for strings in printf X-Git-Tag: 1.1.0~335 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fe8a77e7d13abe5134ad0751e628d73d872b7d45;p=rspamd.git Add support of width modifier for strings in printf --- 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); }