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

@@ -3030,7 +3030,7 @@ parse_stab_argtypes (void *dhandle, struct stab_handle *info,
if (!(is_destructor || is_full_physname_constructor || is_v3))
{
unsigned int len;
unsigned int len, buf_len;
const char *const_prefix;
const char *volatile_prefix;
char buf[20];
@@ -3042,19 +3042,19 @@ parse_stab_argtypes (void *dhandle, struct stab_handle *info,
volatile_prefix = volatilep ? "V" : "";
if (len == 0)
sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
buf_len = sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
else if (tagname != NULL && strchr (tagname, '<') != NULL)
{
/* Template methods are fully mangled. */
sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
buf_len = sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
tagname = NULL;
len = 0;
}
else
sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
buf_len = sprintf (buf, "__%s%s%d", const_prefix, volatile_prefix, len);
mangled_name_len = ((is_constructor ? 0 : strlen (fieldname))
+ strlen (buf)
+ buf_len
+ len
+ strlen (argtypes)
+ 1);