]> source.dussan.org Git - rspamd.git/commitdiff
Add support of width modifier for strings in printf
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 18:31:00 +0000 (18:31 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 10 Dec 2015 18:31:00 +0000 (18:31 +0000)
src/libutil/printf.c

index 11143f79ff2017aa7365cc501295154a9955036e..a6099f83fbb04572511ea92c98acfa2769ac2d4c 100644 (file)
@@ -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);
                                }