public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] gas/config/tc-score7.c: Use strcpy() instead of sprintf()
@ 2014-06-05 20:47 Chen Gang
  2014-06-11  2:41 ` Chen Gang
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2014-06-05 20:47 UTC (permalink / raw)
  To: Andreas Schwab, amodra, matthew.fortune, nickc, Pedro Alves; +Cc: binutils

For several simple string copy operation, strcpy() is better than
sprintf(), so instead of.

Also can avoid one warning (cross compiler score-elf):

  In file included from ../../binutils-gdb/gas/config/tc-score.c:25:0:
  ../../binutils-gdb/gas/config/tc-score7.c: In function ‘s7_parse_pce_inst’:
  ../../binutils-gdb/gas/config/tc-score7.c:5340:7: warning: format not a string literal and no format arguments [-Wformat-security]


Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
---
 gas/config/tc-score7.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c
index 0a0db2d..4719680 100644
--- a/gas/config/tc-score7.c
+++ b/gas/config/tc-score7.c
@@ -2795,7 +2795,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p)
   *p = c;
 
   memset (&s7_inst, '\0', sizeof (s7_inst));
-  sprintf (s7_inst.str, "%s", insnstr);
+  strcpy (s7_inst.str, insnstr);
   if (opcode)
     {
       s7_inst.instruction = opcode->value;
@@ -2804,7 +2804,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p)
       s7_inst.size = s7_GET_INSN_SIZE (s7_inst.type);
       s7_inst.relax_size = 0;
       s7_inst.bwarn = 0;
-      sprintf (s7_inst.name, "%s", opcode->template_name);
+      strcpy (s7_inst.name, opcode->template_name);
       strcpy (s7_inst.reg, "");
       s7_inst.error = NULL;
       s7_inst.reloc.type = BFD_RELOC_NONE;
@@ -5308,12 +5308,12 @@ s7_parse_pce_inst (char *insnstr)
   p = strstr (insnstr, "||");
   c = *p;
   *p = '\0';
-  sprintf (first, "%s", insnstr);
+  strcpy (first, insnstr);
 
   /* Get second part string of PCE.  */
   *p = c;
   p += 2;
-  sprintf (second, "%s", p);
+  strcpy (second, p);
 
   s7_parse_16_32_inst (first, FALSE);
   if (s7_inst.error)
@@ -5337,7 +5337,7 @@ s7_parse_pce_inst (char *insnstr)
       || ((pec_part_1.size == s7_INSN16_SIZE) && (s7_inst.size == s7_INSN_SIZE)))
     {
       s7_inst.error = _("pce instruction error (16 bit || 16 bit)'");
-      sprintf (s7_inst.str, insnstr);
+      strcpy (s7_inst.str, insnstr);
       return;
     }
 
-- 
1.7.11.7

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gas/config/tc-score7.c: Use strcpy() instead of sprintf()
  2014-06-05 20:47 [PATCH v2] gas/config/tc-score7.c: Use strcpy() instead of sprintf() Chen Gang
@ 2014-06-11  2:41 ` Chen Gang
  2014-06-13 14:55   ` Nicholas Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: Chen Gang @ 2014-06-11  2:41 UTC (permalink / raw)
  To: Andreas Schwab, amodra, matthew.fortune, nickc, Pedro Alves; +Cc: binutils

Hello maintainers:

Is this patch OK, please help check it when you have free time, thanks.

Originally, I could not find the related Changelog for 'gas', so I did
not mark change log for it.

Thanks.

On 06/06/2014 04:47 AM, Chen Gang wrote:
> For several simple string copy operation, strcpy() is better than
> sprintf(), so instead of.
> 
> Also can avoid one warning (cross compiler score-elf):
> 
>   In file included from ../../binutils-gdb/gas/config/tc-score.c:25:0:
>   ../../binutils-gdb/gas/config/tc-score7.c: In function ‘s7_parse_pce_inst’:
>   ../../binutils-gdb/gas/config/tc-score7.c:5340:7: warning: format not a string literal and no format arguments [-Wformat-security]
> 
> 
> Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com>
> ---
>  gas/config/tc-score7.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/gas/config/tc-score7.c b/gas/config/tc-score7.c
> index 0a0db2d..4719680 100644
> --- a/gas/config/tc-score7.c
> +++ b/gas/config/tc-score7.c
> @@ -2795,7 +2795,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p)
>    *p = c;
>  
>    memset (&s7_inst, '\0', sizeof (s7_inst));
> -  sprintf (s7_inst.str, "%s", insnstr);
> +  strcpy (s7_inst.str, insnstr);
>    if (opcode)
>      {
>        s7_inst.instruction = opcode->value;
> @@ -2804,7 +2804,7 @@ s7_parse_16_32_inst (char *insnstr, bfd_boolean gen_frag_p)
>        s7_inst.size = s7_GET_INSN_SIZE (s7_inst.type);
>        s7_inst.relax_size = 0;
>        s7_inst.bwarn = 0;
> -      sprintf (s7_inst.name, "%s", opcode->template_name);
> +      strcpy (s7_inst.name, opcode->template_name);
>        strcpy (s7_inst.reg, "");
>        s7_inst.error = NULL;
>        s7_inst.reloc.type = BFD_RELOC_NONE;
> @@ -5308,12 +5308,12 @@ s7_parse_pce_inst (char *insnstr)
>    p = strstr (insnstr, "||");
>    c = *p;
>    *p = '\0';
> -  sprintf (first, "%s", insnstr);
> +  strcpy (first, insnstr);
>  
>    /* Get second part string of PCE.  */
>    *p = c;
>    p += 2;
> -  sprintf (second, "%s", p);
> +  strcpy (second, p);
>  
>    s7_parse_16_32_inst (first, FALSE);
>    if (s7_inst.error)
> @@ -5337,7 +5337,7 @@ s7_parse_pce_inst (char *insnstr)
>        || ((pec_part_1.size == s7_INSN16_SIZE) && (s7_inst.size == s7_INSN_SIZE)))
>      {
>        s7_inst.error = _("pce instruction error (16 bit || 16 bit)'");
> -      sprintf (s7_inst.str, insnstr);
> +      strcpy (s7_inst.str, insnstr);
>        return;
>      }
>  
> 

-- 
Chen Gang

Open, share, and attitude like air, water, and life which God blessed

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] gas/config/tc-score7.c: Use strcpy() instead of sprintf()
  2014-06-11  2:41 ` Chen Gang
@ 2014-06-13 14:55   ` Nicholas Clifton
  0 siblings, 0 replies; 3+ messages in thread
From: Nicholas Clifton @ 2014-06-13 14:55 UTC (permalink / raw)
  To: Chen Gang, Andreas Schwab, amodra, matthew.fortune, Pedro Alves; +Cc: binutils

Hi Chen,

> Is this patch OK, please help check it when you have free time, thanks.

Approved and applied.

> Originally, I could not find the related Changelog for 'gas', so I did
> not mark change log for it.

All patches need a changelog entry so I have created this one for yours:

gas/ChangeLog
2014-06-13  Chen Gang  <gang.chen.5i5j@gmail.com>

	* config/tc-score7.c: Replace sprintf with strcpy where
	appropriate.

Cheers
   Nick

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-06-13 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-05 20:47 [PATCH v2] gas/config/tc-score7.c: Use strcpy() instead of sprintf() Chen Gang
2014-06-11  2:41 ` Chen Gang
2014-06-13 14:55   ` Nicholas Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).