[prev in list] [next in list] [prev in thread] [next in thread]
List: binutils
Subject: [PATCH 3/6] S/390: Fix off-by-one error in disassembler initialization
From: Andreas Arnez <arnez () linux ! vnet ! ibm ! com>
Date: 2014-07-25 17:01:50
Message-ID: 1406307713-7926-4-git-send-email-arnez () linux ! vnet ! ibm ! com
[Download RAW message or body]
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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic