From 4eb3522ecee7da15133c748a4879b62ce309b4df Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Tue, 20 Oct 2026 21:10:36 +0300
Subject: [PATCH 92/92] gtk4(x): Assert notebook page number to remove

See RM #2398

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/gui-gtk-4.0/gui_stuff.c | 6 ++++++
 client/gui-gtk-5.0/gui_stuff.c | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/client/gui-gtk-4.0/gui_stuff.c b/client/gui-gtk-4.0/gui_stuff.c
index 6e2b4036f2..67416abaae 100644
--- a/client/gui-gtk-4.0/gui_stuff.c
+++ b/client/gui-gtk-4.0/gui_stuff.c
@@ -435,6 +435,9 @@ static void gui_dialog_detach(struct gui_dialog *dlg)
   g_signal_handler_disconnect(notebook, handler_id);
 
   n = gtk_notebook_page_num(GTK_NOTEBOOK(dlg->v.tab.notebook), dlg->grid);
+
+  fc_assert(n >= 0);
+
   gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->v.tab.notebook), n);
 
 
@@ -882,6 +885,9 @@ void gui_dialog_destroy(struct gui_dialog *dlg)
       gint n;
 
       n = gtk_notebook_page_num(GTK_NOTEBOOK(dlg->v.tab.notebook), dlg->grid);
+
+      fc_assert(n >= 0);
+
       gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->v.tab.notebook), n);
       g_signal_handler_disconnect(GTK_NOTEBOOK(dlg->v.tab.notebook),
                                   dlg->v.tab.handler_id);
diff --git a/client/gui-gtk-5.0/gui_stuff.c b/client/gui-gtk-5.0/gui_stuff.c
index 09d34f613b..51b3604d74 100644
--- a/client/gui-gtk-5.0/gui_stuff.c
+++ b/client/gui-gtk-5.0/gui_stuff.c
@@ -436,6 +436,9 @@ static void gui_dialog_detach(struct gui_dialog *dlg)
   g_signal_handler_disconnect(notebook, handler_id);
 
   n = gtk_notebook_page_num(GTK_NOTEBOOK(dlg->v.tab.notebook), dlg->grid);
+
+  fc_assert(n >= 0);
+
   gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->v.tab.notebook), n);
 
 
@@ -883,6 +886,9 @@ void gui_dialog_destroy(struct gui_dialog *dlg)
       gint n;
 
       n = gtk_notebook_page_num(GTK_NOTEBOOK(dlg->v.tab.notebook), dlg->grid);
+
+      fc_assert(n >= 0);
+
       gtk_notebook_remove_page(GTK_NOTEBOOK(dlg->v.tab.notebook), n);
       g_signal_handler_disconnect(GTK_NOTEBOOK(dlg->v.tab.notebook),
                                   dlg->v.tab.handler_id);
-- 
2.53.0

