Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2003:
[Freeciv-Dev] Re: (PR#3010) core dump from client air goto
Home

[Freeciv-Dev] Re: (PR#3010) core dump from client air goto

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: per@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#3010) core dump from client air goto
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Thu, 6 Feb 2003 14:46:12 -0800
Reply-to: rt.freeciv.org@xxxxxxxxxxxxxx

This is caused indirectly by the 2837 warmap patch...

warmp_cost is set to either warmap.seacost or warmap.cost at the 
beginning of the function.  But, apparently it is possible that at this 
point warmap.*cost is still not allocated; it gets allocated at some 
point during the function.  And then near the end of the function 
warmap_cost is used.

This worked with the old system because warmap.cost was a static array 
pointing to 200-some-odd dynamic pointers.  So the pointer didn't change 
even when it was allocated.  But the new system has warmap.cost as a 
single pointer to a full-map-sized array, so when it's allocated it is 
changed from NULL to some pointer value.  And warmap_cost is not updated.

The solution is simple: don't set warmap_cost until right before it's used.

I also moved a comment associated with warmap_cost down, and "corrected" 
it somewhat Greg, is this right?).

jason

Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.162
diff -u -r1.162 gotohand.c
--- server/gotohand.c   2003/02/04 23:12:31     1.162
+++ server/gotohand.c   2003/02/06 22:40:40
@@ -561,12 +561,7 @@
   int straight_dir = 0;        /* init to silence compiler warning */
   static unsigned char local_vector[MAP_MAX_WIDTH][MAP_MAX_HEIGHT];
   struct unit *pcargo;
-  /* 
-   * Land/air units use warmap.cost while sea units use
-   * warmap.seacost.  Don't ask me why.  --JDS 
-   */
-  unsigned char *warmap_cost =
-      (move_type == SEA_MOVING) ? warmap.seacost : warmap.cost;
+  unsigned char *warmap_cost;
 
   orig_x = punit->x;
   orig_y = punit->y;
@@ -765,7 +760,11 @@
        die("Bad move_type in find_the_shortest_path().");
       } /****** end switch ******/
 
-      /* Add the route to our warmap if it is worth keeping */
+      /* Add the route to our warmap if it is worth keeping.  Land units
+       * use warmap.cost while sea units use warmap.seacost.  The only
+       * significance is that when making defensive calculations sometimes
+       * both will be used. */
+      warmap_cost = (move_type == SEA_MOVING) ? warmap.seacost : warmap.cost;
       if (total_cost < maxcost) {
        if (warmap_cost[map_inx(x1, y1)] > total_cost) {
          warmap_cost[map_inx(x1, y1)] = total_cost;

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