From: H.J. Lu Date: Tue, 26 May 2020 13:09:54 +0000 (-0700) Subject: tc-score.c: Replace overlapping sprintf with memmove X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a05e3e203954fac0aacfcb647b1f8b52760e6df0;p=binutils-gdb.git tc-score.c: Replace overlapping sprintf with memmove Fix GCC 10 warning: gas/config/tc-score.c:4575:6: error: ‘sprintf’ argument 3 may overlap destination object ‘keep_data’ [-Werror=restrict] 4575 | sprintf (append_str, "bne %s", keep_data); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PR gas/26044 * onfig/tc-score.c (s3_do_macro_bcmp): Replace overlapping sprintf with memmove. --- diff --git a/gas/ChangeLog b/gas/ChangeLog index 7264c8a0619..291a357b157 100644 --- a/gas/ChangeLog +++ b/gas/ChangeLog @@ -1,3 +1,9 @@ +2020-05-26 H.J. Lu + + PR gas/26044 + * onfig/tc-score.c (s3_do_macro_bcmp): Replace overlapping + sprintf with memmove. + 2020-05-25 H.J. Lu * config/tc-mcore.c (md_convert_frag): Replace fragP->fr_literal diff --git a/gas/config/tc-score.c b/gas/config/tc-score.c index 80c4cbfa4eb..72c5de8926c 100644 --- a/gas/config/tc-score.c +++ b/gas/config/tc-score.c @@ -4537,9 +4537,10 @@ s3_do_macro_bcmp (char *str) if (s3_append_insn (append_str, TRUE) == (int) s3_FAIL) goto out; if ((inst_main.instruction & 0x3e00007e) == 0x0000004c) - sprintf (append_str, "beq %s", keep_data); + memcpy (append_str, "beq ", 4); else - sprintf (append_str, "bne %s", keep_data); + memcpy (append_str, "bne ", 4); + memmove (append_str + 4, keep_data, strlen (keep_data) + 1); if (s3_append_insn (append_str, TRUE) == (int) s3_FAIL) goto out; } @@ -4570,9 +4571,10 @@ s3_do_macro_bcmp (char *str) memcpy (&inst_expand[0], &s3_inst, sizeof (struct s3_score_it)); if ((inst_main.instruction & 0x3e00007e) == 0x0000004c) - sprintf (append_str, "beq %s", keep_data); + memcpy (append_str, "beq ", 4); else - sprintf (append_str, "bne %s", keep_data); + memcpy (append_str, "bne ", 4); + memmove (append_str + 4, keep_data, strlen (keep_data) + 1); if (s3_append_insn (append_str, FALSE) == (int) s3_FAIL) goto out; memcpy (&inst_expand[1], &s3_inst, sizeof (struct s3_score_it)); @@ -4685,9 +4687,10 @@ s3_do_macro_bcmpz (char *str) if (s3_append_insn (append_str, TRUE) == (int) s3_FAIL) goto out; if ((inst_main.instruction & 0x3e00007e) == 0x0000004c) - sprintf (append_str, "beq %s", keep_data); + memcpy (append_str, "beq ", 4); else - sprintf (append_str, "bne %s", keep_data); + memcpy (append_str, "bne ", 4); + memmove (append_str + 4, keep_data, strlen (keep_data) + 1); if (s3_append_insn (append_str, TRUE) == (int) s3_FAIL) goto out; } @@ -4717,9 +4720,10 @@ s3_do_macro_bcmpz (char *str) goto out; memcpy (&inst_expand[0], &s3_inst, sizeof (struct s3_score_it)); if ((inst_main.instruction & 0x3e00007e) == 0x0000004c) - sprintf (append_str, "beq %s", keep_data); + memcpy (append_str, "beq ", 4); else - sprintf (append_str, "bne %s", keep_data); + memcpy (append_str, "bne ", 4); + memmove (append_str + 4, keep_data, strlen (keep_data) + 1); if (s3_append_insn (append_str, FALSE) == (int) s3_FAIL) goto out; memcpy (&inst_expand[1], &s3_inst, sizeof (struct s3_score_it));