From 1f27a4a17ba16a8cca21f2bdd09d9eeb0833b71b Mon Sep 17 00:00:00 2001 From: frosch Date: Sat, 6 Aug 2011 17:20:21 +0000 Subject: [PATCH] (svn r22726) -Fix: AITile::GetCargoAcceptance, AITile::GetCargoProduction and AIRail::BuildNewGRFRailStation did not check the cargo argument for validity. --- src/ai/api/ai_rail.cpp | 2 ++ src/ai/api/ai_rail.hpp | 1 + src/ai/api/ai_tile.cpp | 5 +++-- src/ai/api/ai_tile.hpp | 2 ++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/ai/api/ai_rail.cpp b/src/ai/api/ai_rail.cpp index c6aefe7143..8d46065442 100644 --- a/src/ai/api/ai_rail.cpp +++ b/src/ai/api/ai_rail.cpp @@ -14,6 +14,7 @@ #include "ai_map.hpp" #include "ai_station.hpp" #include "ai_industrytype.hpp" +#include "ai_cargo.hpp" #include "../../debug.h" #include "../../station_base.h" #include "../../company_func.h" @@ -170,6 +171,7 @@ EnforcePrecondition(false, platform_length > 0 && platform_length <= 0xFF); EnforcePrecondition(false, IsRailTypeAvailable(GetCurrentRailType())); EnforcePrecondition(false, station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id)); + EnforcePrecondition(false, AICargo::IsValidCargo(cargo_id)); EnforcePrecondition(false, source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry)); EnforcePrecondition(false, goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry)); diff --git a/src/ai/api/ai_rail.hpp b/src/ai/api/ai_rail.hpp index 5f58c3014b..9bb759ea72 100644 --- a/src/ai/api/ai_rail.hpp +++ b/src/ai/api/ai_rail.hpp @@ -279,6 +279,7 @@ public: * @pre num_platforms > 0 && num_platforms <= 255. * @pre platform_length > 0 && platform_length <= 255. * @pre station_id == AIStation::STATION_NEW || station_id == AIStation::STATION_JOIN_ADJACENT || AIStation::IsValidStation(station_id). + * @pre AICargo::IsValidCargo(cargo_type) * @pre source_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || source_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(source_industry). * @pre goal_industry == AIIndustryType::INDUSTRYTYPE_UNKNOWN || goal_industry == AIIndustryType::INDUSTRYTYPE_TOWN || AIIndustryType::IsValidIndustryType(goal_industry). * @exception AIError::ERR_OWNED_BY_ANOTHER_COMPANY diff --git a/src/ai/api/ai_tile.cpp b/src/ai/api/ai_tile.cpp index 3e0b339f77..671567190a 100644 --- a/src/ai/api/ai_tile.cpp +++ b/src/ai/api/ai_tile.cpp @@ -13,6 +13,7 @@ #include "ai_tile.hpp" #include "ai_map.hpp" #include "ai_town.hpp" +#include "ai_cargo.hpp" #include "../../station_func.h" #include "../../company_func.h" #include "../../water_map.h" @@ -192,7 +193,7 @@ /* static */ int32 AITile::GetCargoAcceptance(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0) return -1; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1; CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return acceptance[cargo_type]; @@ -200,7 +201,7 @@ /* static */ int32 AITile::GetCargoProduction(TileIndex tile, CargoID cargo_type, int width, int height, int radius) { - if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0) return -1; + if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !AICargo::IsValidCargo(cargo_type)) return -1; CargoArray produced = ::GetProductionAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); return produced[cargo_type]; diff --git a/src/ai/api/ai_tile.hpp b/src/ai/api/ai_tile.hpp index 944821e007..17a292ae3e 100644 --- a/src/ai/api/ai_tile.hpp +++ b/src/ai/api/ai_tile.hpp @@ -319,6 +319,7 @@ public: * @param height The height of the station. * @param radius The radius of the station. * @pre AIMap::IsValidTile(tile). + * @pre AICargo::IsValidCargo(cargo_type) * @pre width > 0. * @pre height > 0. * @pre radius >= 0. @@ -335,6 +336,7 @@ public: * @param height The height of the station. * @param radius The radius of the station. * @pre AIMap::IsValidTile(tile). + * @pre AICargo::IsValidCargo(cargo_type) * @pre width > 0. * @pre height > 0. * @pre radius >= 0.