From 25ea2de361789e52cc1778a8e23ea5dee8cb29ef Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 19 Apr 2022 04:43:11 +0300 Subject: [PATCH 25/25] gtk select_tgt_*(): Fix compiler warning about use of uninitialized var See osdn #44395 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/unitselextradlg.c | 10 ++++++++-- client/gui-gtk-3.0/unitselunitdlg.c | 10 ++++++++-- client/gui-gtk-3.22/unitselextradlg.c | 10 ++++++++-- client/gui-gtk-3.22/unitselunitdlg.c | 10 ++++++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/client/gui-gtk-3.0/unitselextradlg.c b/client/gui-gtk-3.0/unitselextradlg.c index acd6fca333..fd652149dd 100644 --- a/client/gui-gtk-3.0/unitselextradlg.c +++ b/client/gui-gtk-3.0/unitselextradlg.c @@ -124,7 +124,7 @@ bool select_tgt_extra(struct unit *actor, struct tile *ptile, struct sprite *spr; 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.0/unitselunitdlg.c b/client/gui-gtk-3.0/unitselunitdlg.c index 1540647e2d..7aea0ae66f 100644 --- a/client/gui-gtk-3.0/unitselunitdlg.c +++ b/client/gui-gtk-3.0/unitselunitdlg.c @@ -88,7 +88,7 @@ bool select_tgt_unit(struct unit *actor, struct tile *ptile, struct sprite *spr; 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-3.22/unitselextradlg.c b/client/gui-gtk-3.22/unitselextradlg.c index 2a503a1c28..f419a96972 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; 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 7ed838adc1..5b3e47df7d 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; 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); -- 2.35.1