From eaf6456854f43e083de95825d1d27e793c1f8491 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Sat, 28 Dec 2019 17:30:01 +1100 Subject: [PATCH] Improve efficiency of m_3cat() algorithm Use exact memcpy() instead of repeated strcat(). --- source/ircaux.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/source/ircaux.c b/source/ircaux.c index 0ca4e94..62afac9 100644 --- a/source/ircaux.c +++ b/source/ircaux.c @@ -274,27 +274,27 @@ char *BX_m_s3cat_s (char **one, const char *maybe, const char *ifthere) char *BX_m_3cat(char **one, const char *two, const char *three) { - int len = 0; + size_t one_len = 0, two_len = 0, three_len = 0; char *str; if (*one) - len = strlen(*one); + one_len = strlen(*one); if (two) - len += strlen(two); + two_len = strlen(two); if (three) - len += strlen(three); - len += 1; + three_len = strlen(three); - str = (char *)new_malloc(len); + str = new_malloc(one_len + two_len + three_len + 1); if (*one) - strcpy(str, *one); + memcpy(str, *one, one_len); if (two) - strcat(str, two); + memcpy(str + one_len, two, two_len); if (three) - strcat(str, three); + memcpy(str + one_len + two_len, three, three_len); + str[one_len + two_len + three_len] = 0; new_free(one); - return ((*one = str)); + return (*one = str); } /* upper()