Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2005:
[Freeciv-Dev] Re: (PR#13833) SEGV in movement.c
Home

[Freeciv-Dev] Re: (PR#13833) SEGV in movement.c

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: whraven@xxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#13833) SEGV in movement.c
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 1 Sep 2005 13:38:24 -0700
Reply-to: bugs@xxxxxxxxxxx

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

White Raven wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=13833 >
> 
> CVS version of 1 September 2005:
> 
> Start a game; immediate SEGV.
> 
> It appears that unit class is not properly initialized.  If understand
> correctly, it should be initialized in packhand.c, but it looks like
> there is no corresponding field in the packet_ruleset_unit structure.

Indeed.  This is apparently a long-standing (post-2.0) bug.  The unit 
class isn't sent to the client.  Thus all unit classes were 0 (NULL) 
causing all units to behave (in some ways...not much since the unit 
class doesn't do much yet) like a Missile (crash).

This patch fixes it.  I will commit immediately.

-jason

Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.545
diff -p -u -r1.545 packhand.c
--- client/packhand.c   30 Aug 2005 20:06:27 -0000      1.545
+++ client/packhand.c   1 Sep 2005 20:29:29 -0000
@@ -2073,6 +2073,7 @@ void handle_ruleset_unit(struct packet_r
   sz_strlcpy(u->sound_fight_alt, p->sound_fight_alt);
 
   u->move_type          = p->move_type;
+  u->class = unit_class_get_by_id(p->unit_class_id);
   u->build_cost         = p->build_cost;
   u->pop_cost           = p->pop_cost;
   u->attack_strength    = p->attack_strength;
Index: common/capstr.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/capstr.c,v
retrieving revision 1.268
diff -p -u -r1.268 capstr.c
--- common/capstr.c     25 Aug 2005 19:12:23 -0000      1.268
+++ common/capstr.c     1 Sep 2005 20:29:29 -0000
@@ -82,7 +82,7 @@ const char * const our_capability = our_
  *     as long as possible.  We want to maintain network compatibility with
  *     the stable branch for as long as possible.
  */
-#define CAPABILITY "+Freeciv.Devel.2005.Aug.25"
+#define CAPABILITY "+Freeciv.Devel.2005.Sep.1"
 
 void init_our_capability(void)
 {
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.153
diff -p -u -r1.153 packets.def
--- common/packets.def  20 Aug 2005 19:53:40 -0000      1.153
+++ common/packets.def  1 Sep 2005 20:29:29 -0000
@@ -1042,6 +1042,7 @@ PACKET_RULESET_UNIT=96;sc,lsend
   STRING sound_fight[MAX_LEN_NAME];
   STRING sound_fight_alt[MAX_LEN_NAME];
   UINT8 move_type;
+  UINT8 unit_class_id;
   UINT16 build_cost;
   UINT8 pop_cost;
   UINT8 attack_strength;
Index: common/unittype.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.c,v
retrieving revision 1.68
diff -p -u -r1.68 unittype.c
--- common/unittype.c   1 Sep 2005 02:47:52 -0000       1.68
+++ common/unittype.c   1 Sep 2005 20:29:30 -0000
@@ -686,8 +686,23 @@ void unit_types_free(void)
   } unit_type_iterate_end;
 }
 
+/****************************************************************************
+  Returns unit class structure for an ID value.  Note the possible confusion
+  with get_unit_class.
+****************************************************************************/
+struct unit_class *unit_class_get_by_id(int id)
+{
+  if (id < 0 || id >= UCL_LAST) {
+    return NULL;
+  }
+  return &unit_classes[id];
+}
+
 /***************************************************************
  Returns unit class structure
+
+  FIXME: this function is misnamed and will cause confusion with
+  unit_class_get_by_id.
 ***************************************************************/
 struct unit_class *get_unit_class(const struct unit_type *punittype)
 {
Index: common/unittype.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unittype.h,v
retrieving revision 1.58
diff -p -u -r1.58 unittype.h
--- common/unittype.h   1 Sep 2005 02:47:52 -0000       1.58
+++ common/unittype.h   1 Sep 2005 20:29:30 -0000
@@ -209,6 +209,7 @@ int unit_buy_gold_cost(const struct unit
 int unit_disband_shields(const struct unit_type *punittype);
 int unit_pop_value(const struct unit_type *punittype);
 
+struct unit_class *unit_class_get_by_id(int id);
 struct unit_class *get_unit_class(const struct unit_type *punittype);
 const char *unit_name(const struct unit_type *punittype);
 const char *unit_name_orig(const struct unit_type *punittype);
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.281
diff -p -u -r1.281 ruleset.c
--- server/ruleset.c    1 Sep 2005 02:47:52 -0000       1.281
+++ server/ruleset.c    1 Sep 2005 20:29:31 -0000
@@ -2652,6 +2652,7 @@ static void send_ruleset_units(struct co
     sz_strlcpy(packet.graphic_str, u->graphic_str);
     sz_strlcpy(packet.graphic_alt, u->graphic_alt);
     packet.move_type = u->move_type;
+    packet.unit_class_id = u->class->id;
     packet.build_cost = u->build_cost;
     packet.pop_cost = u->pop_cost;
     packet.attack_strength = u->attack_strength;

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