tc-score.c: Replace overlapping sprintf with memmove

Message ID 20200526131155.93807-1-hjl.tools@gmail.com
State New
Headers show
Series
  • tc-score.c: Replace overlapping sprintf with memmove
Related show

Commit Message

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.
---
 gas/ChangeLog         |  6 ++++++
 gas/config/tc-score.c | 20 ++++++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

-- 
2.26.2

Patch

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 7264c8a061..291a357b15 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,9 @@ 
+2020-05-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR gas/26044
+	* onfig/tc-score.c (s3_do_macro_bcmp): Replace overlapping
+	sprintf with memmove.
+
 2020-05-25  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* 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 80c4cbfa4e..72c5de8926 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));