From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/4] tui-disasm: Fix line buffer size calculation
Date: Tue, 08 Nov 2016 18:59:00 -0000 [thread overview]
Message-ID: <1478631454-9447-3-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1478631454-9447-1-git-send-email-arnez@linux.vnet.ibm.com>
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++)
{
--
2.5.0
next prev parent reply other threads:[~2016-11-08 18:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 18:57 [PATCH 0/4] Some TUI fixes Andreas Arnez
2016-11-08 18:58 ` [PATCH 1/4] tui-disasm: Fix window content buffer overrun Andreas Arnez
2016-11-08 19:29 ` Pedro Alves
2016-11-09 12:07 ` Andreas Arnez
2016-11-08 18:59 ` [PATCH 3/4] tui-winsource: Allocate for actual lines only Andreas Arnez
2016-11-08 19:31 ` Pedro Alves
2016-11-08 18:59 ` Andreas Arnez [this message]
2016-11-08 19:30 ` [PATCH 2/4] tui-disasm: Fix line buffer size calculation Pedro Alves
2016-11-08 19:00 ` [PATCH 4/4] tui-winsource: Remove failed-allocation logic Andreas Arnez
2016-11-08 19:31 ` Pedro Alves
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=1478631454-9447-3-git-send-email-arnez@linux.vnet.ibm.com \
--to=arnez@linux.vnet.ibm.com \
--cc=gdb-patches@sourceware.org \
/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