public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: binutils@sourceware.org
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>,
	       Andreas Krebbel <krebbel@linux.vnet.ibm.com>
Subject: [PATCH 3/6] S/390: Fix off-by-one error in disassembler initialization
Date: Fri, 25 Jul 2014 17:02:00 -0000	[thread overview]
Message-ID: <1406307713-7926-4-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1406307713-7926-1-git-send-email-arnez@linux.vnet.ibm.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

  parent reply	other threads:[~2014-07-25 17:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-25 17:02 [PATCH 0/6] S/390: Some disassembler cleanup Andreas Arnez
2014-07-25 17:02 ` [PATCH 5/6] S/390: Drop function pointer dereferences in disassembler Andreas Arnez
2014-07-25 17:02 ` [PATCH 4/6] S/390: Simplify opcode search loop " Andreas Arnez
2014-07-25 17:02 ` Andreas Arnez [this message]
2014-07-25 17:02 ` [PATCH 6/6] S/390: Various minor simplifications " Andreas Arnez
2014-07-25 17:02 ` [PATCH 1/6] S/390: Split disassembler routine into smaller functions Andreas Arnez
2014-07-25 17:02 ` [PATCH 2/6] S/390: Fix disassembler's treatment of signed/unsigned operands Andreas Arnez
2014-08-19 14:43 ` [PATCH 0/6] S/390: Some disassembler cleanup Nicholas Clifton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1406307713-7926-4-git-send-email-arnez@linux.vnet.ibm.com \
    --to=arnez@linux.vnet.ibm.com \
    --cc=binutils@sourceware.org \
    --cc=krebbel@linux.vnet.ibm.com \
    --cc=schwidefsky@de.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).