This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] gas/config/tc-tic4x.c: Let insn name full use its space and always zero terminated

strncpy() can not be sure of insn name must be zero terminated, so need
set it explicitly.

At present, insn name is only used in tic4x_insn_check() which only test
insn name within 9 chars explicitly. So it is harmless to use full space
of insn name for strncpy().

 - tic4x_insn_t is defined within this file, and "tc-tic4x.c" is not
   included by other files, so can only consider about tic4x_insn_t
   within "c-tic4x.c".

 - after search "tic4x_insn_t", can be sure only tic4x_insn_check() use
   insn name. And 'the_insn' is only be referenced by 'insn'.

 - after search "insn", can sure insn name is set only in md_assemble().

2014-11-17  Chen Gang  <>

	* config/tc-tic4x.c (md_assemble): Let insn name full use its
	space and always zero terminated.
 gas/config/tc-tic4x.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gas/config/tc-tic4x.c b/gas/config/tc-tic4x.c
index 12d8ec9..d1ceec0 100644
--- a/gas/config/tc-tic4x.c
+++ b/gas/config/tc-tic4x.c
@@ -2518,7 +2518,8 @@ md_assemble (char *str)
       if (*s)			/* Null terminate for hash_find.  */
 	*s++ = '\0';		/* and skip past null.  */
-      strncpy (insn->name, str, TIC4X_NAME_MAX - 3);
+      strncpy (insn->name, str, TIC4X_NAME_MAX - 1);
+      insn->name[TIC4X_NAME_MAX - 1] = '\0';
       if ((i = tic4x_operands_parse (s, insn->operands, 0)) < 0)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]