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.
This commit is contained in:
Alan Modra
2023-08-03 12:32:40 +09:30
parent 75747be51e
commit ad923ded82
7 changed files with 67 additions and 69 deletions

View File

@@ -186,9 +186,9 @@ look_for_prog (const char *progname, const char *prefix, int end_prefix)
+ strlen (EXECUTABLE_SUFFIX)
#endif
+ 10);
strcpy (cmd, prefix);
memcpy (cmd, prefix, end_prefix);
sprintf (cmd + end_prefix, "%s", progname);
strcpy (cmd + end_prefix, progname);
if (strchr (cmd, '/') != NULL)
{