(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place gamebalance
authorcelestar
Wed, 21 Mar 2007 15:12:30 +0000
branchgamebalance
changeset 9900 750202458d8b
parent 9899 cde52f745560
child 9901 a922f277ebfd
(svn r9389) [gamebalance] -Fix(r9332): I should not use uninitialized variables and shall also find out why my g++ didn't warn me in the first place
src/town.cpp
--- a/src/town.cpp	Wed Mar 21 11:46:54 2007 +0000
+++ b/src/town.cpp	Wed Mar 21 15:12:30 2007 +0000
@@ -6,13 +6,14 @@
 #include "openttd.h"
 #include "road_map.h"
 #include "town.h"
+#include "town_map.h"
 
 /* static */
 const Town *Town::GetRadiusGroupForTile(TileIndex tile, uint &group)
 {
 	const Town *t;
 	group = 0;
-	const Town *best_town;
+	const Town *best_town = NULL;
 
 	DEBUG(eco, 7, "Obtaining highest town radius for tile 0x%x", tile);
 
@@ -20,6 +21,7 @@
 	if (IsTileType(tile, MP_HOUSE) ||
 			(IsTileType(tile, MP_STREET) &&
 			(IsLevelCrossing(tile) ? GetCrossingRoadOwner(tile) : GetTileOwner(tile)) == OWNER_TOWN)) {
+		t = GetTownByTile(tile);
 		group = t->GetRadiusGroup(tile, true) + 1;
 		DEBUG(eco, 6, "Tile 0x%x belongs to town at 0x%x, level %d", tile, t->xy, group);
 		return t;
@@ -33,6 +35,8 @@
 		}
 	}
 
+	assert(best_town != NULL);
+
 	return best_town;
 }