summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2013-02-05 21:38:38 +0000
committerpeter1138 <peter1138@openttd.org>2013-02-05 21:38:38 +0000
commit3b4f4fe0b6d2da93d15b2d1015f068ebeba1943e (patch)
treef8646422c0e7497458dc81854e4052bbc6b8807f /src
parent00530f4ccfd6c076b9ca0d4996ce4a185b5a0311 (diff)
downloadopenttd-3b4f4fe0b6d2da93d15b2d1015f068ebeba1943e.tar.xz
(svn r24973) -Fix [FS#5462]: Prevent access to tile-based variables when tile is invalid.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_industries.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp
index dd8c81c1f..257e27df1 100644
--- a/src/newgrf_industries.cpp
+++ b/src/newgrf_industries.cpp
@@ -225,7 +225,9 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
}
/* Manhattan distance of closes dry/water tile */
- case 0x43: return GetClosestWaterDistance(this->tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
+ case 0x43:
+ if (this->tile == INVALID_TILE) break;
+ return GetClosestWaterDistance(this->tile, (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) == 0);
/* Layout number */
case 0x44: return this->industry->selected_layout;
@@ -253,15 +255,19 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
/* Get random tile bits at offset param */
case 0x61: {
+ if (this->tile == INVALID_TILE) break;
TileIndex tile = GetNearbyTile(parameter, this->tile, false);
return this->industry->TileBelongsToIndustry(tile) ? GetIndustryRandomBits(tile) : 0;
}
/* Land info of nearby tiles */
- case 0x62: return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro->grffile->grf_version >= 8);
+ case 0x62:
+ if (this->tile == INVALID_TILE) break;
+ return GetNearbyIndustryTileInformation(parameter, this->tile, INVALID_INDUSTRY, false, this->ro->grffile->grf_version >= 8);
/* Animation stage of nearby tiles */
case 0x63: {
+ if (this->tile == INVALID_TILE) break;
TileIndex tile = GetNearbyTile(parameter, this->tile, false);
if (this->industry->TileBelongsToIndustry(tile)) {
return GetAnimationFrame(tile);
@@ -270,11 +276,17 @@ static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte layout
}
/* Distance of nearest industry of given type */
- case 0x64: return GetClosestIndustry(this->tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), this->industry);
+ case 0x64:
+ if (this->tile == INVALID_TILE) break;
+ return GetClosestIndustry(this->tile, MapNewGRFIndustryType(parameter, indspec->grf_prop.grffile->grfid), this->industry);
/* Get town zone and Manhattan distance of closest town */
- case 0x65: return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceManhattan(this->tile, this->industry->town->xy), 0xFFFF);
+ case 0x65:
+ if (this->tile == INVALID_TILE) break;
+ return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceManhattan(this->tile, this->industry->town->xy), 0xFFFF);
/* Get square of Euclidian distance of closes town */
- case 0x66: return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceSquare(this->tile, this->industry->town->xy), 0xFFFF);
+ case 0x66:
+ if (this->tile == INVALID_TILE) break;
+ return GetTownRadiusGroup(this->industry->town, this->tile) << 16 | min(DistanceSquare(this->tile, this->industry->town->xy), 0xFFFF);
/* Count of industry, distance of closest instance
* 68 is the same as 67, but with a filtering on selected layout */