<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39722 >

Indeed, this is officially a gcc bug, explained in 39459 in more detail.

https://bugzilla.novell.com/show_bug.cgi?id=300410

Nonetheless I see no problem with working around it (as 39459 did).  In
general we should strive to remove pointer-to-int casts like this as
they seem to be an ongoing problem.

The attached patch removes the (bad) assumption that CMA_NONE is -1,
changes CMA_NONE and CMA_CUSTOM to be positive (it doesn't use the
cmafec_preset_num value as this is variable), and adds an assertion to
trigger if there's a problem.  I will commit to all branches (without
the assertion for 2.1).

-jason

Index: client/gui-gtk-2.0/cityrep.c
===================================================================
--- client/gui-gtk-2.0/cityrep.c	(revision 14078)
+++ client/gui-gtk-2.0/cityrep.c	(working copy)
@@ -52,9 +52,11 @@
 #include "cityrep.h"
 
 #define NEG_VAL(x)  ((x)<0 ? (x) : (-x))
-#define CMA_NONE	(-1)
-#define CMA_CUSTOM	(-2)
 
+/* Some versions of gcc have problems with negative values here (PR#39722). */
+#define CMA_NONE	(10000)
+#define CMA_CUSTOM	(10001)
+
 enum city_operation_type {
   CO_CHANGE, CO_LAST, CO_NEXT, CO_FIRST, CO_NONE
 };
@@ -542,12 +544,18 @@
   gtk_menu_item_set_submenu(parent_item, menu);
 
   if (change_cma) {
-    for (i = -1; i < cmafec_preset_num(); i++) {
-      w = (i == -1 ? gtk_menu_item_new_with_label(_("none"))
-	   : gtk_menu_item_new_with_label(cmafec_preset_get_descr(i)));
+    w = gtk_menu_item_new_with_label(_("none"));
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu), w);
+    g_signal_connect(w, "activate", G_CALLBACK(select_cma_callback),
+		     GINT_TO_POINTER(CMA_NONE));
+    assert(GPOINTER_TO_INT(GINT_TO_POINTER(CMA_NONE)) == CMA_NONE);
+
+    for (i = 0; i < cmafec_preset_num(); i++) {
+      w = gtk_menu_item_new_with_label(cmafec_preset_get_descr(i));
       gtk_menu_shell_append(GTK_MENU_SHELL(menu), w);
       g_signal_connect(w, "activate", G_CALLBACK(select_cma_callback),
 		       GINT_TO_POINTER(i));
+      assert(GPOINTER_TO_INT(GINT_TO_POINTER(i)) == i);
     }
   } else {
     /* search for a "none" */
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to