summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-09-04 20:02:35 +0000
committerrubidium <rubidium@openttd.org>2009-09-04 20:02:35 +0000
commit925bada35a7ad71834630f4c9bbaef2c24bc4dfb (patch)
tree8ad6fb0f00c4e267ab3719a1d08881d8a3d60efa
parentfcbdd9c7306796b1044bdd2826a04498f4de938d (diff)
downloadopenttd-925bada35a7ad71834630f4c9bbaef2c24bc4dfb.tar.xz
(svn r17413) -Fix: assert when trying to build an invalid industry type it did
-rw-r--r--src/industry_cmd.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index 6a8ba32b7..a485dd75e 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -1678,7 +1678,10 @@ static Industry *CreateNewIndustryHelper(TileIndex tile, IndustryType type, DoCo
*/
CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- const IndustrySpec *indspec = GetIndustrySpec(GB(p1, 0, 16));
+ IndustryType it = GB(p1, 0, 16);
+ if (it >= NUM_INDUSTRYTYPES) return CMD_ERROR;
+
+ const IndustrySpec *indspec = GetIndustrySpec(it);
const Industry *ind = NULL;
/* Check if the to-be built/founded industry is available for this climate. */
@@ -1717,7 +1720,8 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
} else {
int count = indspec->num_table;
const IndustryTileTable * const *itt = indspec->table;
- int num = Clamp(GB(p1, 16, 16), 0, count - 1);
+ int num = GB(p1, 16, 16);
+ if (num >= count) return CMD_ERROR;
_error_message = STR_ERROR_SITE_UNSUITABLE;
do {