From a6fcd5432e495aea416ebae28d44111eadf19b82 Mon Sep 17 00:00:00 2001 From: ailin-nemui Date: Tue, 13 Feb 2018 12:31:22 +0100 Subject: improve padding performance Credit to Oss-Fuzz --- src/core/special-vars.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/special-vars.c b/src/core/special-vars.c index f254c200..e131b0ed 100644 --- a/src/core/special-vars.c +++ b/src/core/special-vars.c @@ -337,11 +337,14 @@ char *get_alignment(const char *text, int align, int flags, char pad) /* add pad characters */ if (flags & ALIGN_PAD) { - while (string_width(str->str, policy) < align) { + int pad_len = align - string_width(str->str, policy); + if (pad_len > 0) { + char *pad_full = g_strnfill(pad_len, pad); if (flags & ALIGN_RIGHT) - g_string_prepend_c(str, pad); + g_string_prepend(str, pad_full); else - g_string_append_c(str, pad); + g_string_append(str, pad_full); + g_free(pad_full); } } -- cgit v1.2.3