Convert strcat() calls which only append single characters
to the end of res into simpler (and most likely cheaper)
single assignment statements.

Signed-off-by: Joey Pabalinas <joeypabali...@gmail.com>

 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index cca9663be5ddd91870..67600f48660f2ac142 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -910,8 +910,7 @@ char *sym_expand_string_value(const char *in)
         * freed, so make sure to always allocate a new string
         */
        reslen = strlen(in) + 1;
-       res = xmalloc(reslen);
-       res[0] = '\0';
+       res = xcalloc(1, reslen);
 
        while ((src = strchr(in, '$'))) {
                char *p, name[SYMBOL_MAXLENGTH];
@@ -951,7 +950,7 @@ const char *sym_escape_string_value(const char *in)
 {
        const char *p;
        size_t reslen;
-       char *res;
+       char *res, *end;
        size_t l;
 
        reslen = strlen(in) + strlen("\"\"") + 1;
@@ -968,25 +967,25 @@ const char *sym_escape_string_value(const char *in)
                p++;
        }
 
-       res = xmalloc(reslen);
-       res[0] = '\0';
-
-       strcat(res, "\"");
+       res = xcalloc(1, reslen);
+       end = res;
+       *end++ = '\"';
 
        p = in;
        for (;;) {
                l = strcspn(p, "\"\\");
                strncat(res, p, l);
                p += l;
+               end += l;
 
                if (p[0] == '\0')
                        break;
 
-               strcat(res, "\\");
-               strncat(res, p++, 1);
+               *end++ = '\\';
+               *end++ = *p++;
        }
+       *end = '\"';
 
-       strcat(res, "\"");
        return res;
 }
 
-- 
2.16.2

Sorry about the double send, clipboards are very fickle beasts :(

Attachment: signature.asc
Description: PGP signature

Reply via email to