From dfec1b9278c70ff13c6a2e1de30b16f2a8f82b83 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 19 Apr 2022 04:40:22 +0300 Subject: [PATCH 51/51] gtk select_tgt_*(): Fix compiler warning about use of uninitialized var See osdn #44395 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.22/unitselextradlg.c | 10 ++++++++-- client/gui-gtk-3.22/unitselunitdlg.c | 10 ++++++++-- client/gui-gtk-4.0/unitselextradlg.c | 10 ++++++++-- client/gui-gtk-4.0/unitselunitdlg.c | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/gui-gtk-3.22/unitselextradlg.c b/client/gui-gtk-3.22/unitselextradlg.c index 330b8668db..c735ac095b 100644 --- a/client/gui-gtk-3.22/unitselextradlg.c +++ b/client/gui-gtk-3.22/unitselextradlg.c @@ -124,7 +124,7 @@ bool select_tgt_extra(struct unit *actor, struct tile *ptile, struct sprite *spr; const struct unit_type *actor_type = unit_type_get(actor); int tcount; - const struct extra_type *default_extra; + const struct extra_type *default_extra = NULL; dlg = gtk_dialog_new_with_buttons(dlg_title, NULL, 0, _("Close"), GTK_RESPONSE_NO, @@ -229,7 +229,13 @@ bool select_tgt_extra(struct unit *actor, struct tile *ptile, g_object_set_data(G_OBJECT(dlg), "actor", GINT_TO_POINTER(actor->id)); g_object_set_data(G_OBJECT(dlg), "tile", ptile); - g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_extra->id)); + + /* This function should never be called so that there would be no extra to select, + * and where there is extra to select, one of them gets selected as the default. */ + fc_assert(default_extra != NULL); + if (default_extra != NULL) { /* Compiler still wants this */ + g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_extra->id)); + } g_signal_connect(dlg, "response", do_callback, actor); diff --git a/client/gui-gtk-3.22/unitselunitdlg.c b/client/gui-gtk-3.22/unitselunitdlg.c index c2bbc30726..eb013237f2 100644 --- a/client/gui-gtk-3.22/unitselunitdlg.c +++ b/client/gui-gtk-3.22/unitselunitdlg.c @@ -88,7 +88,7 @@ bool select_tgt_unit(struct unit *actor, struct tile *ptile, struct sprite *spr; const struct unit_type *actor_type = unit_type_get(actor); int tcount; - const struct unit *default_unit; + const struct unit *default_unit = NULL; dlg = gtk_dialog_new_with_buttons(dlg_title, NULL, 0, _("Close"), GTK_RESPONSE_NO, @@ -189,7 +189,13 @@ bool select_tgt_unit(struct unit *actor, struct tile *ptile, g_object_set_data(G_OBJECT(dlg), "actor", GINT_TO_POINTER(actor->id)); g_object_set_data(G_OBJECT(dlg), "tile", ptile); - g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_unit->id)); + + /* This function should never be called so that there would be no unit to select, + * and where there is unit to select, one of them gets selected as the default. */ + fc_assert(default_unit != NULL); + if (default_unit != NULL) { /* Compiler still wants this */ + g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_unit->id)); + } g_signal_connect(dlg, "response", do_callback, actor); diff --git a/client/gui-gtk-4.0/unitselextradlg.c b/client/gui-gtk-4.0/unitselextradlg.c index abce9dbcbd..409b3dc46a 100644 --- a/client/gui-gtk-4.0/unitselextradlg.c +++ b/client/gui-gtk-4.0/unitselextradlg.c @@ -124,7 +124,7 @@ bool select_tgt_extra(struct unit *actor, struct tile *ptile, struct sprite *spr; const struct unit_type *actor_type = unit_type_get(actor); int tcount; - const struct extra_type *default_extra; + const struct extra_type *default_extra = NULL; int main_row = 0; dlg = gtk_dialog_new_with_buttons(dlg_title, NULL, 0, @@ -222,7 +222,13 @@ bool select_tgt_extra(struct unit *actor, struct tile *ptile, g_object_set_data(G_OBJECT(dlg), "actor", GINT_TO_POINTER(actor->id)); g_object_set_data(G_OBJECT(dlg), "tile", ptile); - g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_extra->id)); + + /* This function should never be called so that there would be no extra to select, + * and where there is extra to select, one of them gets selected as the default. */ + fc_assert(default_extra != NULL); + if (default_extra != NULL) { /* Compiler still wants this */ + g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_extra->id)); + } g_signal_connect(dlg, "response", do_callback, actor); diff --git a/client/gui-gtk-4.0/unitselunitdlg.c b/client/gui-gtk-4.0/unitselunitdlg.c index b561b0de30..cfdf43e4db 100644 --- a/client/gui-gtk-4.0/unitselunitdlg.c +++ b/client/gui-gtk-4.0/unitselunitdlg.c @@ -88,7 +88,7 @@ bool select_tgt_unit(struct unit *actor, struct tile *ptile, struct sprite *spr; const struct unit_type *actor_type = unit_type_get(actor); int tcount; - const struct unit *default_unit; + const struct unit *default_unit = NULL; int main_row = 0; dlg = gtk_dialog_new_with_buttons(dlg_title, NULL, 0, @@ -182,7 +182,13 @@ bool select_tgt_unit(struct unit *actor, struct tile *ptile, g_object_set_data(G_OBJECT(dlg), "actor", GINT_TO_POINTER(actor->id)); g_object_set_data(G_OBJECT(dlg), "tile", ptile); - g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_unit->id)); + + /* This function should never be called so that there would be no unit to select, + * and where there is unit to select, one of them gets selected as the default. */ + fc_assert(default_unit != NULL); + if (default_unit != NULL) { /* Compiler still wants this */ + g_object_set_data(G_OBJECT(dlg), "target", GINT_TO_POINTER(default_unit->id)); + } g_signal_connect(dlg, "response", do_callback, actor); -- 2.35.1