This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] gas/config/tc-tic4x.c: Let insn name full use its space and always zero terminated
- From: Chen Gang <gang dot chen dot 5i5j at gmail dot com>
- To: binutils at sourceware dot org, amodra at gmail dot com
- Date: Mon, 17 Nov 2014 23:47:08 +0800
- Subject: [PATCH] gas/config/tc-tic4x.c: Let insn name full use its space and always zero terminated
- Authentication-results: sourceware.org; auth=none
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 <gang.chen.5i5j@gmail.com>
* 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)
s++;
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)
{
--
1.9.3