Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2005:
[Freeciv-Dev] (PR#13488) T_UNKNOWN errors in 2.0
Home

[Freeciv-Dev] (PR#13488) T_UNKNOWN errors in 2.0

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#13488) T_UNKNOWN errors in 2.0
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 18 Jul 2005 10:14:52 -0700
Reply-to: bugs@xxxxxxxxxxx

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

This patch demonstrates errors with T_UNKNOWN for 2.0.

1.  An assertion catches any out-of-range tile deferences in
get_tile_type.  This triggers immediately in the client when T_UNKNOWN
is dereferenced.

2.  The tile_types array is allocated at runtime instead of statically.
 When run under valgrind this should allow detection of buffer underrun
errors when T_UNKNOWN is looked up directly.  In 2.0 there are a lot of
users that don't use get_tile_type so this is needed to catch those errors.

This is a likely cause of freeciv-crashes-at-startup errors reported on
some platforms.  I'll send a patch to fix the errors shortly.

-jason

? ChangeLog-2.0.0
? diff
? freeciv-2.0.3.tar.gz
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.187.2.3
diff -p -u -r1.187.2.3 game.c
--- common/game.c       3 May 2005 03:21:24 -0000       1.187.2.3
+++ common/game.c       18 Jul 2005 17:10:21 -0000
@@ -284,6 +284,7 @@ void game_init(void)
   map_init();
   idex_init();
   cm_init();
+  tile_types = fc_calloc(MAX_NUM_TERRAINS, sizeof(*tile_types));
   
   for(i=0; i<MAX_NUM_PLAYERS+MAX_NUM_BARBARIANS; i++)
     player_init(&game.players[i]);
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.219.2.6
diff -p -u -r1.219.2.6 map.h
--- common/map.h        18 Mar 2005 19:19:04 -0000      1.219.2.6
+++ common/map.h        18 Jul 2005 17:10:21 -0000
@@ -136,7 +136,7 @@ struct tile_type {
 
   char *helptext;
 };
-extern struct tile_type tile_types[MAX_NUM_TERRAINS];
+extern struct tile_type *tile_types;
 
 /* The direction8 gives the 8 possible directions.  These may be used in
  * a number of ways, for instance as an index into the DIR_DX/DIR_DY
Index: common/terrain.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/terrain.c,v
retrieving revision 1.16
diff -p -u -r1.16 terrain.c
--- common/terrain.c    29 Sep 2004 02:24:23 -0000      1.16
+++ common/terrain.c    18 Jul 2005 17:10:21 -0000
@@ -24,13 +24,14 @@
 #include "support.h"
 #include "terrain.h"
 
-struct tile_type tile_types[MAX_NUM_TERRAINS];
+struct tile_type *tile_types;
 
 /***************************************************************
 ...
 ***************************************************************/
 struct tile_type *get_tile_type(Terrain_type_id type)
 {
+  assert(type >= 0 && type < T_COUNT);
   return &tile_types[type];
 }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#13488) T_UNKNOWN errors in 2.0, Jason Short <=