aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-08-03 12:26:46 +0930
committerAlan Modra <amodra@gmail.com>2023-08-03 21:20:33 +0930
commit75747be51e6d11287e12c4504f2607d36a0edfd2 (patch)
tree70a1c0bcca2476bf85da5733a56c4015ac8353f6
parentb43e801e28550653ecef2b7e6b15125516ab1a58 (diff)
downloadgdb-75747be51e6d11287e12c4504f2607d36a0edfd2.zip
gdb-75747be51e6d11287e12c4504f2607d36a0edfd2.tar.gz
gdb-75747be51e6d11287e12c4504f2607d36a0edfd2.tar.bz2
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.
-rw-r--r--opcodes/cris-dis.c29
1 files changed, 10 insertions, 19 deletions
diff --git a/opcodes/cris-dis.c b/opcodes/cris-dis.c
index 681fccf..27a7003 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. */