summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2005-10-12 09:54:29 +0000
committerpeter1138 <peter1138@openttd.org>2005-10-12 09:54:29 +0000
commit5551b423fc4e6b6f7365c8e59272c755d8c3bde9 (patch)
treef5a7c1c6a6479ae68b002a2fc606e9aff5153826
parent0321dc9fc5c3d6aa9944ddd75a3f0e20745bcb86 (diff)
downloadopenttd-5551b423fc4e6b6f7365c8e59272c755d8c3bde9.tar.xz
(svn r3034) -NewGRF: Improve error checking of setting price bases.
-rw-r--r--economy.c8
-rw-r--r--economy.h2
-rw-r--r--newgrf.c7
3 files changed, 11 insertions, 6 deletions
diff --git a/economy.c b/economy.c
index fd19a592c..2e2b45a22 100644
--- a/economy.c
+++ b/economy.c
@@ -775,7 +775,7 @@ static byte price_base_multiplier[NUM_PRICES];
*/
void ResetPriceBaseMultipliers(void)
{
- int i;
+ uint i;
// 8 means no multiplier.
for (i = 0; i < NUM_PRICES; i++)
@@ -789,10 +789,10 @@ void ResetPriceBaseMultipliers(void)
* @param price Index of price base to change.
* @param factor Amount to change by.
*/
-void SetPriceBaseMultiplier(int price, byte factor)
+void SetPriceBaseMultiplier(uint price, byte factor)
{
- if (price < NUM_PRICES)
- price_base_multiplier[price] = factor;
+ assert(price < NUM_PRICES);
+ price_base_multiplier[price] = factor;
}
void StartupEconomy(void)
diff --git a/economy.h b/economy.h
index 11336be03..02afd8075 100644
--- a/economy.h
+++ b/economy.h
@@ -4,7 +4,7 @@
#define ECONOMY_H
void ResetPriceBaseMultipliers(void);
-void SetPriceBaseMultiplier(int price, byte factor);
+void SetPriceBaseMultiplier(uint price, byte factor);
typedef struct {
// Maximum possible loan
diff --git a/newgrf.c b/newgrf.c
index 0693bcea1..e0876c8ec 100644
--- a/newgrf.c
+++ b/newgrf.c
@@ -1070,8 +1070,13 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i
case 0x08: { /* Cost base factor */
FOR_EACH_OBJECT {
byte factor = grf_load_byte(&buf);
+ uint price = gvid + i;
- SetPriceBaseMultiplier(gvid + i, factor);
+ if (price < NUM_PRICES) {
+ SetPriceBaseMultiplier(price, factor);
+ } else {
+ grfmsg(GMS_WARN, "GlobalVarChangeInfo: Price %d out of range, ignoring.", price);
+ }
}
} break;
default: