Complete.Org: Mailing Lists: Archives: freeciv-dev: August 2005:
[Freeciv-Dev] Re: (PR#13595) pubserver crash: MAP_NCONT is overrun
Home

[Freeciv-Dev] Re: (PR#13595) pubserver crash: MAP_NCONT is overrun

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13595) pubserver crash: MAP_NCONT is overrun
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 3 Aug 2005 11:09:34 -0700
Reply-to: bugs@xxxxxxxxxxx

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

For 2.1 we should just use this patch that removes MAP_NCONT.

For 2.0 we should increase NCONT and list this in the known bugs.

-jason


Index: server/maphand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.c,v
retrieving revision 1.170
diff -p -u -r1.170 maphand.c
--- server/maphand.c    14 Jul 2005 19:25:46 -0000      1.170
+++ server/maphand.c    3 Aug 2005 18:08:36 -0000
@@ -41,13 +41,18 @@
 
 #define MAXIMUM_CLAIMED_OCEAN_SIZE (20)
 
-/* Continent which is adjacent to a given ocean. -1 if the ocean is surrounded
-   by more than one continent */
-static Continent_id lake_surrounders[MAP_NCONT];
-/* size of a given continent in tiles */
-static int continent_sizes[MAP_NCONT];
-/* size of a given ocean in tiles */
-static int ocean_sizes[MAP_NCONT];
+/* These arrays are indexed by continent number (or negative of the
+ * ocean number) so the 0th element is unused and the array is 1 element
+ * larger than you'd expect.
+ *
+ * The lake surrounders array tells how many land continents surround each
+ * ocean (or -1 if the ocean touches more than one continent).
+ *
+ * The _sizes arrays give the sizes (in tiles) of each continent and
+ * ocean.
+ */
+static Continent_id *lake_surrounders;
+static int *continent_sizes, *ocean_sizes;
 
 /**************************************************************************
   Number this tile and nearby tiles (recursively) with the specified
@@ -99,11 +104,10 @@ static void assign_continent_flood(struc
 **************************************************************************/
 static void recalculate_lake_surrounders(void)
 {
-  int i;
+  const size_t size = (map.num_oceans + 1) * sizeof(*lake_surrounders);
 
-  for (i = 1; i <= map.num_oceans; i++) {
-    lake_surrounders[i] = 0;
-  }
+  lake_surrounders = fc_realloc(lake_surrounders, size);
+  memset(lake_surrounders, 0, size);
   
   whole_map_iterate(ptile) {
     Continent_id cont = tile_get_continent(ptile);
@@ -136,13 +140,6 @@ static void recalculate_lake_surrounders
 **************************************************************************/
 void assign_continent_numbers(bool skip_unsafe)
 {
-  int i;
-  
-  /* reset ocean/continent counters */
-  for (i = 0; i < MAP_NCONT; i++) {
-    ocean_sizes[i] = 0;
-    continent_sizes[i] = 0;
-  }
   
   /* Initialize */
   map.num_continents = 0;
@@ -168,11 +165,17 @@ void assign_continent_numbers(bool skip_
     if (!skip_unsafe || !terrain_has_flag(pterrain, TER_UNSAFE)) {
       if (!is_ocean(pterrain)) {
        map.num_continents++;
-       assert(map.num_continents < MAP_NCONT);
+       continent_sizes
+         = fc_realloc(continent_sizes,
+                      (map.num_continents + 1) * sizeof(*continent_sizes));
+       continent_sizes[map.num_continents] = 0;
        assign_continent_flood(ptile, TRUE, map.num_continents, skip_unsafe);
       } else {
        map.num_oceans++;
-       assert(map.num_oceans < MAP_NCONT);
+       ocean_sizes
+         = fc_realloc(ocean_sizes,
+                      (map.num_oceans + 1) * sizeof(*ocean_sizes));
+       ocean_sizes[map.num_oceans] = 0;
        assign_continent_flood(ptile, FALSE, -map.num_oceans, skip_unsafe);
       }
     }
Index: server/maphand.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/maphand.h,v
retrieving revision 1.59
diff -p -u -r1.59 maphand.h
--- server/maphand.h    14 Jul 2005 19:25:46 -0000      1.59
+++ server/maphand.h    3 Aug 2005 18:08:36 -0000
@@ -53,9 +53,6 @@ struct player_tile {
   short last_updated;
 };
 
-/* The maximum number of continents and oceans. */
-#define MAP_NCONT 600
-
 void assign_continent_numbers(bool skip_unsafe);
 
 void global_warming(int effect);
Index: server/generator/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/generator/mapgen.c,v
retrieving revision 1.30
diff -p -u -r1.30 mapgen.c
--- server/generator/mapgen.c   1 Aug 2005 22:38:26 -0000       1.30
+++ server/generator/mapgen.c   3 Aug 2005 18:08:36 -0000
@@ -1703,11 +1703,6 @@ static bool make_island(int islemass, in
     /* makes the islands this big */
     islemass = islemass - balance;
 
-    /* don't create continents without a number */
-    if (pstate->isleindex >= MAP_NCONT) {
-      return FALSE;
-    }
-
     if (islemass > lastplaced + 1 + lastplaced / 50) {
       /* don't create big isles we can't place */
       islemass = lastplaced + 1 + lastplaced / 50;
@@ -1989,19 +1984,18 @@ static void mapgenerator3(void)
     islandmass= 2;
   }
 
-  while (pstate->isleindex <= MAP_NCONT - 20 && checkmass > islandmass &&
-         ++j < 1500) {
-      if (j < 1000) {
-       size = myrand((islandmass+1)/2+1)+islandmass/2;
-      } else {
-       size = myrand((islandmass+1)/2+1);
-      }
-      if (size < 2) {
-        size=2;
-      }
+  while (checkmass > islandmass && ++j < 1500) {
+    if (j < 1000) {
+      size = myrand((islandmass+1)/2+1)+islandmass/2;
+    } else {
+      size = myrand((islandmass+1)/2+1);
+    }
+    if (size < 2) {
+      size=2;
+    }
 
-      make_island(size, (pstate->isleindex - 2 <= game.info.nplayers) ? 1 : 0,
-                 pstate, DMSIS);
+    make_island(size, (pstate->isleindex - 2 <= game.info.nplayers) ? 1 : 0,
+               pstate, DMSIS);
   }
 
   make_plains();  

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