From patchwork Tue Nov 8 18:56:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 17297 Received: (qmail 9006 invoked by alias); 8 Nov 2016 18:59:05 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 8996 invoked by uid 89); 8 Nov 2016 18:59:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_SEMBACKSCATTER autolearn=no version=3.3.2 spammy=yields, 1787, (unknown), 2039 X-HELO: mx0a-001b2d01.pphosted.com Received: from mx0a-001b2d01.pphosted.com (HELO mx0a-001b2d01.pphosted.com) (148.163.156.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 Nov 2016 18:59:02 +0000 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uA8IwYu3009340 for ; Tue, 8 Nov 2016 13:59:01 -0500 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 26kgfxqtyh-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 08 Nov 2016 13:59:00 -0500 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 8 Nov 2016 18:58:58 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 8 Nov 2016 18:58:56 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 09C32219004D for ; Tue, 8 Nov 2016 18:58:10 +0000 (GMT) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uA8IwtVw42729526 for ; Tue, 8 Nov 2016 18:58:55 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id uA8Hwvrd020276 for ; Tue, 8 Nov 2016 10:58:57 -0700 Received: from oc1027705133.ibm.com (dyn-9-152-212-182.boeblingen.de.ibm.com [9.152.212.182]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id uA8Hvan9019676 for ; Tue, 8 Nov 2016 10:58:57 -0700 From: Andreas Arnez To: gdb-patches@sourceware.org Subject: [PATCH 2/4] tui-disasm: Fix line buffer size calculation Date: Tue, 8 Nov 2016 19:56:52 +0100 In-Reply-To: <1478631454-9447-1-git-send-email-arnez@linux.vnet.ibm.com> References: <1478631454-9447-1-git-send-email-arnez@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16110818-0040-0000-0000-00000302350C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16110818-0041-0000-0000-00001DCBE5E9 Message-Id: <1478631454-9447-3-git-send-email-arnez@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-11-08_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611080344 X-IsSubscribed: yes The code that fills the TUI disassembly window content first calculates the maximum full length of a displayed disassembly line. This calculation typically yields the wrong result. The result is too large, so the bug does not cause any run-time failures, but unnecessary confusion for the reader. This patch fixes the calculation. gdb/ChangeLog: * tui/tui-disasm.c (tui_set_disassem_content): Fix calculation of the longest disassembly line's length. --- gdb/tui/tui-disasm.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/gdb/tui/tui-disasm.c b/gdb/tui/tui-disasm.c index 5368aa4..6811be3 100644 --- a/gdb/tui/tui-disasm.c +++ b/gdb/tui/tui-disasm.c @@ -178,7 +178,7 @@ tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc) int tab_len = tui_default_tab_len (); struct tui_asm_line *asm_lines; int insn_pos; - int addr_size, max_size; + int addr_size, insn_size; char *line; if (pc == 0) @@ -203,9 +203,9 @@ tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc) tui_disassemble (gdbarch, asm_lines, pc, max_lines); - /* See what is the maximum length of an address and of a line. */ + /* Determine maximum address- and instruction lengths. */ addr_size = 0; - max_size = 0; + insn_size = 0; for (i = 0; i < max_lines; i++) { size_t len = strlen (asm_lines[i].addr_string); @@ -213,16 +213,17 @@ tui_set_disassem_content (struct gdbarch *gdbarch, CORE_ADDR pc) if (len > addr_size) addr_size = len; - len = strlen (asm_lines[i].insn) + tab_len; - if (len > max_size) - max_size = len; + len = strlen (asm_lines[i].insn); + if (len > insn_size) + insn_size = len; } - max_size += addr_size + tab_len; - /* Allocate memory to create each line. */ - line = (char*) alloca (max_size); + /* Align instructions to the same column. */ insn_pos = (1 + (addr_size / tab_len)) * tab_len; + /* Allocate memory to create each line. */ + line = (char*) alloca (insn_pos + insn_size + 1); + /* Now construct each line. */ for (i = 0; i < max_lines; i++) {