Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 3/4] tui-winsource: Allocate for actual lines only
Date: Tue, 08 Nov 2016 18:59:00 -0000	[thread overview]
Message-ID: <1478631454-9447-4-git-send-email-arnez@linux.vnet.ibm.com> (raw)
In-Reply-To: <1478631454-9447-1-git-send-email-arnez@linux.vnet.ibm.com>

The logic for allocating a TUI source window's content buffer allocates
two more lines than needed, because it does not reduce the window height
by the highlight box's overhead.  However, it does reduce the line width
accordingly.  This patch makes the height and width calculation
consistent and improves the comment.

gdb/ChangeLog:

	* tui/tui-winsource.c (tui_alloc_source_buffer): Subtract
	highlight box's overhead when calculating the content height.
---
 gdb/tui/tui-winsource.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index 09080b8..4a82ae4 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -604,8 +604,11 @@ tui_alloc_source_buffer (struct tui_win_info *win_info)
   char *src_line_buf;
   int i, line_width, max_lines;
 
-  max_lines = win_info->generic.height;	/* Less the highlight box.  */
-  line_width = win_info->generic.width - 1;
+  /* The window width/height includes the highlight box.  Determine actual
+     content dimensions, including string null-terminators.  */
+  max_lines = win_info->generic.height - 2;
+  line_width = win_info->generic.width - 2 + 1;
+
   /*
    * Allocate the buffer for the source lines.  Do this only once
    * since they will be re-used for all source displays.  The only
-- 
2.5.0


  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 ` Andreas Arnez [this message]
2016-11-08 19:31   ` [PATCH 3/4] tui-winsource: Allocate for actual lines only Pedro Alves
2016-11-08 18:59 ` [PATCH 2/4] tui-disasm: Fix line buffer size calculation Andreas Arnez
2016-11-08 19:30   ` 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-4-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