[binutils-gdb] gdb/tui: convert a window handle `if` into an `assert`

Andrew Burgess via Gdb-cvs <[email protected]> Mon, 27 Jul 2026 13:48:47 +0000 (GMT)
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D000bc9ac78b9=
c4a5d39398d9e74013cd9ca95874

commit 000bc9ac78b9c4a5d39398d9e74013cd9ca95874
Author: Andrew Burgess <[email protected]>
Date:   Mon Apr 27 21:18:56 2026 +0100

    gdb/tui: convert a window handle `if` into an `assert`
   =20
    It should only be possible to call tui_win_info::refresh_window on a
    window with a valid handle member.  To do otherwise would suggest
    we're trying to draw to the screen a window which GDB doesn't think is
    part of the current layout, which is just wrong.
   =20
    Currently tui_win_info::refresh_window guards its content with an
    `if (handle !=3D NULL)`, but this can be changed to an assert.
   =20
    A similar assert can be added to
    tui_source_window_base::refresh_window, there's no `if` in this
    function, which only backs up the reasoning in the first paragraph.
   =20
    There should be no user-visible changes after this commit.

Diff:
---
 gdb/tui/tui-wingeneral.c | 13 ++++++-------
 gdb/tui/tui-winsource.c  |  2 ++
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c
index 149ca4efc6e..281c56d475e 100644
--- a/gdb/tui/tui-wingeneral.c
+++ b/gdb/tui/tui-wingeneral.c
@@ -55,13 +55,12 @@ tui_batch_rendering::~tui_batch_rendering ()
 void
 tui_win_info::refresh_window ()
 {
-  if (handle !=3D NULL)
-    {
-      if (suppress_output)
-	wnoutrefresh (handle.get ());
-      else
-	wrefresh (handle.get ());
-    }
+  gdb_assert (handle !=3D nullptr);
+
+  if (suppress_output)
+    wnoutrefresh (handle.get ());
+  else
+    wrefresh (handle.get ());
 }
=20
 /* Draw a border around the window.  */
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index e3f64892e27..c7149ff7c80 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -310,6 +310,8 @@ tui_source_window_base::refresh_window ()
 {
   TUI_SCOPED_DEBUG_START_END ("window `%s`", name ());
=20
+  gdb_assert (handle !=3D nullptr);
+
   /* tui_win_info::refresh_window would draw the empty background window to
      the screen, potentially creating a flicker.  */
   wnoutrefresh (handle.get ());