diff options
author | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2018-02-13 12:31:22 +0100 |
---|---|---|
committer | ailin-nemui <ailin-nemui@users.noreply.github.com> | 2018-02-13 12:31:22 +0100 |
commit | a6fcd5432e495aea416ebae28d44111eadf19b82 (patch) | |
tree | 6ff23f3838b6021c7629404f944bb6dc351c189c | |
parent | c01f6df9573f3a5596bdb4c319faa109567f4221 (diff) | |
download | irssi-a6fcd5432e495aea416ebae28d44111eadf19b82.zip |
improve padding performance
Credit to Oss-Fuzz
-rw-r--r-- | src/core/special-vars.c | 9 |
1 files 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); } } |