Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#9779) gui-xaw segfault on A_UNSET
Home

[Freeciv-Dev] (PR#9779) gui-xaw segfault on A_UNSET

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9779) gui-xaw segfault on A_UNSET
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 23 Sep 2004 13:20:33 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9779 >

The problem is get_tech_name segfaults if you give it A_UNSET. 
Obviously this is bad since it already handles A_NOINFO and A_FUTURE.

This patch fixes get_tech_name as well as two "bad" callers that Egor
pointed out in the gtk clients.  I didn't change the XAW or any other
clients.

In future users should not call advances[t].name.  Call get_tech_name
instead.  I tried a quick grep for users of this but there were too many
to deal with.

jason

Index: client/gui-gtk/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/gui_main.c,v
retrieving revision 1.151
diff -u -r1.151 gui_main.c
--- client/gui-gtk/gui_main.c   6 Sep 2004 17:13:06 -0000       1.151
+++ client/gui-gtk/gui_main.c   23 Sep 2004 20:18:20 -0000
@@ -1092,8 +1092,9 @@
            game.player_ptr->economic.tax,
            game.player_ptr->economic.luxury,
            game.player_ptr->economic.science,
-           
-           advances[game.player_ptr->research.researching].name,
+
+           get_tech_name(game.player_ptr,
+                         game.player_ptr->research.researching),
            game.player_ptr->research.bulbs_researched,
            total_bulbs_required(game.player_ptr),
            get_government_name(game.player_ptr->government));
Index: client/gui-gtk-2.0/gui_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/gui_main.c,v
retrieving revision 1.79
diff -u -r1.79 gui_main.c
--- client/gui-gtk-2.0/gui_main.c       19 Sep 2004 00:22:11 -0000      1.79
+++ client/gui-gtk-2.0/gui_main.c       23 Sep 2004 20:18:20 -0000
@@ -1312,8 +1312,9 @@
            game.player_ptr->economic.tax,
            game.player_ptr->economic.luxury,
            game.player_ptr->economic.science,
-           
-           advances[game.player_ptr->research.researching].name,
+
+           get_tech_name(game.player_ptr,
+                         game.player_ptr->research.researching),
            game.player_ptr->research.bulbs_researched,
            total_bulbs_required(game.player_ptr),
            get_government_name(game.player_ptr->government));
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.75
diff -u -r1.75 tech.c
--- common/tech.c       2 Aug 2004 23:19:36 -0000       1.75
+++ common/tech.c       23 Sep 2004 20:18:21 -0000
@@ -575,15 +575,28 @@
 {
   static char buffer[200];
 
-  if (tech == A_NOINFO) {
+  switch (tech) {
+  case A_NOINFO:
     my_snprintf(buffer, sizeof(buffer), _("(Unknown)"));
-  } else if (!is_future_tech(tech)) {
-    assert(tech_exists(tech));
-    my_snprintf(buffer, sizeof(buffer), "%s", advances[tech].name);
-  } else {
+    break;
+  case A_UNSET:
+    my_snprintf(buffer, sizeof(buffer), _("None"));
+    break;
+  case A_FUTURE:
     my_snprintf(buffer, sizeof(buffer), _("Future Tech. %d"),
                pplayer->future_tech + 1);
+    break;
+  default:
+    /* Includes A_NONE */
+    if (!tech_exists(tech)) {
+      assert(0);
+      my_snprintf(buffer, sizeof(buffer), _("(Unknown)"));
+    } else {
+      my_snprintf(buffer, sizeof(buffer), "%s", advances[tech].name);
+    }
+    break;
   }
+
   return buffer;
 }
 

[Prev in Thread] Current Thread [Next in Thread]