diff options
author | Alan Modra <amodra@gmail.com> | 2023-08-03 12:32:40 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-08-03 21:20:33 +0930 |
commit | ad923ded82d0ede5a2506a9fbd0f5a5a6728e1a6 (patch) | |
tree | 60fc72cb334c014f1aed431154cf8f35d224135e /binutils/resrc.c | |
parent | 75747be51e6d11287e12c4504f2607d36a0edfd2 (diff) | |
download | fsf-binutils-gdb-ad923ded82d0ede5a2506a9fbd0f5a5a6728e1a6.zip fsf-binutils-gdb-ad923ded82d0ede5a2506a9fbd0f5a5a6728e1a6.tar.gz fsf-binutils-gdb-ad923ded82d0ede5a2506a9fbd0f5a5a6728e1a6.tar.bz2 |
binutils sprintf optimisation
Avoid the use of sprintf with a "%s" format string, replacing with
strcpy or stpcpy. Use sprintf return value rather than a later
strlen. Don't use strcat where we can keep track of the end of a
string output buffer.
* dlltool.c (look_for_prog): memcpy prefix and strcpy prog_name.
* dllwrap.c (look_for_prog): Likewise.
* resrc.c (look_for_default): Likewise. Add quotes with memmove
rather than allocating another buffer.
* size.c (size_number): Use sprintf return value.
* stabs.c (parse_stab_argtypes): Likewise.
* windmc.c (write_bin): Likewes, and use stpcpy.
* wrstabs.c: Similarly throughout.
Diffstat (limited to 'binutils/resrc.c')
-rw-r--r-- | binutils/resrc.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/binutils/resrc.c b/binutils/resrc.c index 0d7a6e1..468e2fd 100644 --- a/binutils/resrc.c +++ b/binutils/resrc.c @@ -383,9 +383,9 @@ look_for_default (char *cmd, const char *prefix, int end_prefix, struct stat s; const char *fnquotes = (filename_need_quotes (filename) ? "\"" : ""); - strcpy (cmd, prefix); + memcpy (cmd, prefix, end_prefix); - sprintf (cmd + end_prefix, "%s", DEFAULT_PREPROCESSOR_CMD); + char *out = stpcpy (cmd + end_prefix, DEFAULT_PREPROCESSOR_CMD); if ( #if defined (__DJGPP__) || defined (__CYGWIN__) || defined (_WIN32) @@ -409,13 +409,13 @@ look_for_default (char *cmd, const char *prefix, int end_prefix, if (filename_need_quotes (cmd)) { - char *cmd_copy = xmalloc (strlen (cmd)); - strcpy (cmd_copy, cmd); - sprintf (cmd, "\"%s\"", cmd_copy); - free (cmd_copy); + memmove (cmd + 1, cmd, out - cmd); + cmd[0] = '"'; + out++; + *out++ = '"'; } - sprintf (cmd + strlen (cmd), " %s %s %s%s%s", + sprintf (out, " %s %s %s%s%s", DEFAULT_PREPROCESSOR_ARGS, preprocargs, fnquotes, filename, fnquotes); if (verbose) |