From ad923ded82d0ede5a2506a9fbd0f5a5a6728e1a6 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 3 Aug 2023 12:32:40 +0930 Subject: 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. --- binutils/size.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'binutils/size.c') diff --git a/binutils/size.c b/binutils/size.c index 9473897..243c740 100644 --- a/binutils/size.c +++ b/binutils/size.c @@ -441,11 +441,9 @@ size_number (bfd_size_type num) { char buffer[40]; - sprintf (buffer, (radix == decimal ? "%" PRIu64 - : radix == octal ? "0%" PRIo64 : "0x%" PRIx64), - (uint64_t) num); - - return strlen (buffer); + return sprintf (buffer, (radix == decimal ? "%" PRIu64 + : radix == octal ? "0%" PRIo64 : "0x%" PRIx64), + (uint64_t) num); } static void -- cgit v1.1