scripts/kconfig: replace single character strcat() appends
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.
Signed-off-by Joey Pabalinas <[email protected]>
1 file changed, 9 insertions(+), 10 deletions(-)
scripts/kconfig/symbol.c +9 -10
@@ -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