From 75747be51e6d11287e12c4504f2607d36a0edfd2 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Thu, 3 Aug 2023 12:26:46 +0930 Subject: [PATCH] cris: sprintf optimisation Since I was poking at cris-dis.c to avoid the sanitizer warning, I figure I might as well make use of stpcpy and sprintf return value in other places in this file. * cris-dis.c (format_hex): Use sprintf return value. (format_reg): Use stpcpy and sprintf return, avoiding strlen. (format_sup_reg): Likewise. --- opcodes/cris-dis.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/opcodes/cris-dis.c b/opcodes/cris-dis.c index 681fccf0dca..27a7003188e 100644 --- a/opcodes/cris-dis.c +++ b/opcodes/cris-dis.c @@ -563,13 +563,11 @@ format_hex (unsigned long number, /* Truncate negative numbers on >32-bit hosts. */ number &= 0xffffffff; - sprintf (outbuffer, "0x%lx", number); - /* Save this value for the "case" support. */ if (TRACE_CASE) last_immediate = number; - return outbuffer + strlen (outbuffer); + return outbuffer + sprintf (outbuffer, "0x%lx", number); } /* Format number as decimal into outbuffer. Parameter signedp says @@ -588,11 +586,9 @@ format_dec (long number, char *outbuffer, int signedp) static char * format_reg (struct cris_disasm_data *disdata, int regno, - char *outbuffer_start, + char *outbuffer, bool with_reg_prefix) { - char *outbuffer = outbuffer_start; - if (with_reg_prefix) *outbuffer++ = REGISTER_PREFIX_CHAR; @@ -601,31 +597,30 @@ format_reg (struct cris_disasm_data *disdata, case 15: /* For v32, there is no context in which we output PC. */ if (disdata->distype == cris_dis_v32) - strcpy (outbuffer, "acr"); + outbuffer = stpcpy (outbuffer, "acr"); else - strcpy (outbuffer, "pc"); + outbuffer = stpcpy (outbuffer, "pc"); break; case 14: - strcpy (outbuffer, "sp"); + outbuffer = stpcpy (outbuffer, "sp"); break; default: - sprintf (outbuffer, "r%d", regno); + outbuffer += sprintf (outbuffer, "r%d", regno); break; } - return outbuffer_start + strlen (outbuffer_start); + return outbuffer; } /* Format the name of a support register into outbuffer. */ static char * format_sup_reg (unsigned int regno, - char *outbuffer_start, + char *outbuffer, bool with_reg_prefix) { - char *outbuffer = outbuffer_start; int i; if (with_reg_prefix) @@ -633,15 +628,11 @@ format_sup_reg (unsigned int regno, for (i = 0; cris_support_regs[i].name != NULL; i++) if (cris_support_regs[i].number == regno) - { - sprintf (outbuffer, "%s", cris_support_regs[i].name); - return outbuffer_start + strlen (outbuffer_start); - } + return stpcpy (outbuffer, cris_support_regs[i].name); /* There's supposed to be register names covering all numbers, though some may be generic names. */ - sprintf (outbuffer, "format_sup_reg-BUG"); - return outbuffer_start + strlen (outbuffer_start); + return stpcpy (outbuffer, "format_sup_reg-BUG"); } /* Return the length of an instruction. */ -- 2.30.2