Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2005:
[Freeciv-Dev] (PR#14176) client cityrep crash
Home

[Freeciv-Dev] (PR#14176) client cityrep crash

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#14176) client cityrep crash
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 3 Oct 2005 15:59:38 -0700
Reply-to: bugs@xxxxxxxxxxx

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

get_city_dialog_production_row can apparently take a NULL city when used 
by the cityrep.  This patch fixes the crash in this function (changing 
some of its helper functions to function better) and documentes it.

Without this the cityrep will always crash.  I will commit immediately.

-jason

? data/nation/old
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.86
diff -p -u -r1.86 citydlg_common.c
--- client/citydlg_common.c     3 Oct 2005 02:50:42 -0000       1.86
+++ client/citydlg_common.c     3 Oct 2005 22:54:21 -0000
@@ -295,7 +295,7 @@ void get_city_dialog_production_full(cha
 /**************************************************************************
  Pretty sprints the info about a production in 4 columns (name, info,
  cost, turns to build). The columns must each have a size of
- column_size bytes.
+ column_size bytes.  City may be NULL.
 **************************************************************************/
 void get_city_dialog_production_row(char *buf[], size_t column_size,
                                    struct city_production target,
@@ -318,7 +318,7 @@ void get_city_dialog_production_row(char
     }
     my_snprintf(buf[2], column_size, "%d", unit_build_shield_cost(ptype));
   } else {
-    struct player *pplayer = pcity->owner;
+    struct player *pplayer = pcity ? pcity->owner : game.player_ptr;
 
     /* Total & turns left meaningless on capitalization */
     if (building_has_effect(target.value, EFT_PROD_TO_GOLD)) {
Index: common/improvement.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/improvement.c,v
retrieving revision 1.68
diff -p -u -r1.68 improvement.c
--- common/improvement.c        11 Aug 2005 02:39:03 -0000      1.68
+++ common/improvement.c        3 Oct 2005 22:54:35 -0000
@@ -439,6 +439,9 @@ struct city *find_city_from_great_wonder
 struct city *find_city_from_small_wonder(const struct player *pplayer,
                                         Impr_type_id id)
 {
+  if (!pplayer) {
+    return NULL; /* Used in some places in the client. */
+  }
   return (player_find_city_by_id(pplayer, pplayer->small_wonders[id]));
 }
 
Index: common/tech.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/tech.c,v
retrieving revision 1.101
diff -p -u -r1.101 tech.c
--- common/tech.c       3 Oct 2005 02:50:45 -0000       1.101
+++ common/tech.c       3 Oct 2005 22:54:35 -0000
@@ -53,7 +53,8 @@ static const char *flag_names[] = {
   This can be: TECH_KNOW, TECH_UNKNOWN or TECH_REACHABLE
   Should be called with existing techs or A_FUTURE
 
-  If pplayer is NULL this simply returns TECH_KNOWN (used by the client).
+  If pplayer is NULL this checks whether any player knows the tech (used
+  by the client).
 **************************************************************************/
 enum tech_state get_invention(const struct player *pplayer,
                              Tech_type_id tech)
@@ -62,7 +63,11 @@ enum tech_state get_invention(const stru
          || (tech >= 0 && tech < game.control.num_tech_types));
 
   if (!pplayer) {
-    return TECH_KNOWN;
+    if (tech != A_FUTURE && game.info.global_advances[tech]) {
+      return TECH_KNOWN;
+    } else {
+      return TECH_UNKNOWN;
+    }
   } else {
     return get_player_research(pplayer)->inventions[tech].state;
   }

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#14176) client cityrep crash, Jason Short <=