summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorailin-nemui <ailin-nemui@users.noreply.github.com>2018-02-13 12:31:22 +0100
committerailin-nemui <ailin-nemui@users.noreply.github.com>2018-02-13 12:31:22 +0100
commita6fcd5432e495aea416ebae28d44111eadf19b82 (patch)
tree6ff23f3838b6021c7629404f944bb6dc351c189c /src/core
parentc01f6df9573f3a5596bdb4c319faa109567f4221 (diff)
downloadirssi-a6fcd5432e495aea416ebae28d44111eadf19b82.zip
improve padding performance
Credit to Oss-Fuzz
Diffstat (limited to 'src/core')
-rw-r--r--src/core/special-vars.c9
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);
}
}