public inbox for linux-kbuild@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/kconfig: replace single character strcat() appends
@ 2018-03-02  7:38 Joey Pabalinas
  0 siblings, 0 replies; 6+ messages in thread
From: Joey Pabalinas @ 2018-03-02  7:38 UTC (permalink / raw)
  To: linux-kbuild; +Cc: Arnaud Lacombe, Masahiro Yamada, kernel, Joey Pabalinas

[-- Attachment #1: Type: text/plain, Size: 1500 bytes --]

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 <joeypabalinas@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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread
* [PATCH] scripts/kconfig: replace single character strcat() appends
@ 2018-03-02  7:44 Joey Pabalinas
  2018-03-02 13:44 ` Ulf Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Joey Pabalinas @ 2018-03-02  7:44 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Arnaud Lacombe, Masahiro Yamada, Linux Kernel Mailing List,
	Joey Pabalinas

[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]

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 <joeypabalinas@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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-03-03 18:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-02  7:38 [PATCH] scripts/kconfig: replace single character strcat() appends Joey Pabalinas
  -- strict thread matches above, loose matches on Subject: below --
2018-03-02  7:44 Joey Pabalinas
2018-03-02 13:44 ` Ulf Magnusson
2018-03-02 23:12   ` Joey Pabalinas
2018-03-03 18:14     ` Ulf Magnusson
2018-03-03 18:23       ` Ulf Magnusson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox