From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5520 invoked by alias); 25 Jul 2014 17:02:11 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 5461 invoked by uid 89); 25 Jul 2014 17:02:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp17.uk.ibm.com Received: from e06smtp17.uk.ibm.com (HELO e06smtp17.uk.ibm.com) (195.75.94.113) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 25 Jul 2014 17:02:01 +0000 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 25 Jul 2014 18:01:58 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 25 Jul 2014 18:01:56 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id AE88717D8047 for ; Fri, 25 Jul 2014 18:03:36 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s6PH1ucK34275418 for ; Fri, 25 Jul 2014 17:01:56 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s6PH1s1X023207 for ; Fri, 25 Jul 2014 11:01:55 -0600 Received: from br87z6lw.boeblingen.de.ibm.com (dyn-9-152-212-196.boeblingen.de.ibm.com [9.152.212.196]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s6PH1r7C023174; Fri, 25 Jul 2014 11:01:54 -0600 From: Andreas Arnez To: binutils@sourceware.org Cc: Martin Schwidefsky , Andreas Krebbel Subject: [PATCH 3/6] S/390: Fix off-by-one error in disassembler initialization Date: Fri, 25 Jul 2014 17:02:00 -0000 Message-Id: <1406307713-7926-4-git-send-email-arnez@linux.vnet.ibm.com> In-Reply-To: <1406307713-7926-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1406307713-7926-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14072517-0542-0000-0000-0000002C3682 X-SW-Source: 2014-07/txt/msg00203.txt.bz2 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