This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH 3/6] S/390: Fix off-by-one error in disassembler initialization
- From: Andreas Arnez <arnez at linux dot vnet dot ibm dot com>
- To: binutils at sourceware dot org
- Cc: Martin Schwidefsky <schwidefsky at de dot ibm dot com>, Andreas Krebbel <krebbel at linux dot vnet dot ibm dot com>
- Date: Fri, 25 Jul 2014 19:01:50 +0200
- Subject: [PATCH 3/6] S/390: Fix off-by-one error in disassembler initialization
- Authentication-results: sourceware.org; auth=none
- References: <1406307713-7926-1-git-send-email-arnez at linux dot vnet dot ibm dot com>
opcodes/
* s390-dis.c (init_disasm): Simplify initialization of
opc_index[]. This also fixes an access after the last element of
s390_opcodes[].
---
opcodes/s390-dis.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 47c449a..e6b0ee5 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -35,19 +35,15 @@ static int current_arch_mask = 0;
static void
init_disasm (struct disassemble_info *info)
{
- const struct s390_opcode *opcode;
- const struct s390_opcode *opcode_end;
+ int i;
const char *p;
memset (opc_index, 0, sizeof (opc_index));
- opcode_end = s390_opcodes + s390_num_opcodes;
- for (opcode = s390_opcodes; opcode < opcode_end; opcode++)
- {
- opc_index[(int) opcode->opcode[0]] = opcode - s390_opcodes;
- while ((opcode < opcode_end) &&
- (opcode[1].opcode[0] == opcode->opcode[0]))
- opcode++;
- }
+
+ /* Reverse order, such that each opc_index ends up pointing to the
+ first matching entry instead of the last. */
+ for (i = s390_num_opcodes; i--; )
+ opc_index[s390_opcodes[i].opcode[0]] = i;
for (p = info->disassembler_options; p != NULL; )
{
--
1.8.4.2