Skip to contentSkip to conversation

scripts/kconfig: replace single character strcat() appends

PATCH New Joey Pabalinas 1 participant 1 message Mar 2, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts/kconfig: replace single character strcat() appends

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

 1 file changed, 9 insertions(+), 10 deletions(-)
scripts/kconfig/symbol.c +9 -10
index cca9663be5ddd91870..67600f48660f2ac142 100644
@@ -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;
 }
 
Signature · 1 line
2.16.2