Skip to content

Commit 75747be

Browse files
committed
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.
1 parent b43e801 commit 75747be

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

opcodes/cris-dis.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -563,13 +563,11 @@ format_hex (unsigned long number,
563563
/* Truncate negative numbers on >32-bit hosts. */
564564
number &= 0xffffffff;
565565

566-
sprintf (outbuffer, "0x%lx", number);
567-
568566
/* Save this value for the "case" support. */
569567
if (TRACE_CASE)
570568
last_immediate = number;
571569

572-
return outbuffer + strlen (outbuffer);
570+
return outbuffer + sprintf (outbuffer, "0x%lx", number);
573571
}
574572

575573
/* Format number as decimal into outbuffer. Parameter signedp says
@@ -588,11 +586,9 @@ format_dec (long number, char *outbuffer, int signedp)
588586
static char *
589587
format_reg (struct cris_disasm_data *disdata,
590588
int regno,
591-
char *outbuffer_start,
589+
char *outbuffer,
592590
bool with_reg_prefix)
593591
{
594-
char *outbuffer = outbuffer_start;
595-
596592
if (with_reg_prefix)
597593
*outbuffer++ = REGISTER_PREFIX_CHAR;
598594

@@ -601,47 +597,42 @@ format_reg (struct cris_disasm_data *disdata,
601597
case 15:
602598
/* For v32, there is no context in which we output PC. */
603599
if (disdata->distype == cris_dis_v32)
604-
strcpy (outbuffer, "acr");
600+
outbuffer = stpcpy (outbuffer, "acr");
605601
else
606-
strcpy (outbuffer, "pc");
602+
outbuffer = stpcpy (outbuffer, "pc");
607603
break;
608604

609605
case 14:
610-
strcpy (outbuffer, "sp");
606+
outbuffer = stpcpy (outbuffer, "sp");
611607
break;
612608

613609
default:
614-
sprintf (outbuffer, "r%d", regno);
610+
outbuffer += sprintf (outbuffer, "r%d", regno);
615611
break;
616612
}
617613

618-
return outbuffer_start + strlen (outbuffer_start);
614+
return outbuffer;
619615
}
620616

621617
/* Format the name of a support register into outbuffer. */
622618

623619
static char *
624620
format_sup_reg (unsigned int regno,
625-
char *outbuffer_start,
621+
char *outbuffer,
626622
bool with_reg_prefix)
627623
{
628-
char *outbuffer = outbuffer_start;
629624
int i;
630625

631626
if (with_reg_prefix)
632627
*outbuffer++ = REGISTER_PREFIX_CHAR;
633628

634629
for (i = 0; cris_support_regs[i].name != NULL; i++)
635630
if (cris_support_regs[i].number == regno)
636-
{
637-
sprintf (outbuffer, "%s", cris_support_regs[i].name);
638-
return outbuffer_start + strlen (outbuffer_start);
639-
}
631+
return stpcpy (outbuffer, cris_support_regs[i].name);
640632

641633
/* There's supposed to be register names covering all numbers, though
642634
some may be generic names. */
643-
sprintf (outbuffer, "format_sup_reg-BUG");
644-
return outbuffer_start + strlen (outbuffer_start);
635+
return stpcpy (outbuffer, "format_sup_reg-BUG");
645636
}
646637

647638
/* Return the length of an instruction. */

0 commit comments

Comments
 (0)