Complete.Org: Mailing Lists: Archives: freeciv-dev: December 1999:
[Freeciv-Dev] segfault patch
Home

[Freeciv-Dev] segfault patch

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] segfault patch
From: Patrik Järnefelt <pja@xxxxxxxxxx>
Date: Thu, 9 Dec 1999 18:06:00 +0100 (MET)

Warmap.cost (& .seacost & .vector) isn't always allocated (start a
singleplayer game without ai) so a call to init_gotomap prior to any
allocation done in init_warmap will lead to segfault.

.p.

Index: server/gotohand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/gotohand.c,v
retrieving revision 1.45
diff -u -r1.45 gotohand.c
--- gotohand.c  1999/11/29 20:59:24     1.45
+++ gotohand.c  1999/12/09 16:42:51
@@ -387,6 +387,14 @@
 {
   int x;
 
+  if (!warmap.cost[0]) {
+    for (x = 0; x < map.xsize; x++) {
+      warmap.cost[x]=fc_malloc(map.ysize*sizeof(unsigned char));
+      warmap.seacost[x]=fc_malloc(map.ysize*sizeof(unsigned char));
+      warmap.vector[x]=fc_malloc(map.ysize*sizeof(unsigned char));
+    }
+  }
+
   for (x = 0; x < map.xsize; x++) {
     memset(warmap.cost[x],255,map.ysize*sizeof(unsigned char));
     memset(warmap.seacost[x],255,map.ysize*sizeof(unsigned char));

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