1
0
Fork 0

(svn r3034) -NewGRF: Improve error checking of setting price bases.

release/0.4.5
peter1138 2005-10-12 09:54:29 +00:00
parent 0321dc9fc5
commit 5551b423fc
3 changed files with 11 additions and 6 deletions

View File

@ -775,7 +775,7 @@ static byte price_base_multiplier[NUM_PRICES];
*/ */
void ResetPriceBaseMultipliers(void) void ResetPriceBaseMultipliers(void)
{ {
int i; uint i;
// 8 means no multiplier. // 8 means no multiplier.
for (i = 0; i < NUM_PRICES; i++) for (i = 0; i < NUM_PRICES; i++)
@ -789,9 +789,9 @@ void ResetPriceBaseMultipliers(void)
* @param price Index of price base to change. * @param price Index of price base to change.
* @param factor Amount to change by. * @param factor Amount to change by.
*/ */
void SetPriceBaseMultiplier(int price, byte factor) void SetPriceBaseMultiplier(uint price, byte factor)
{ {
if (price < NUM_PRICES) assert(price < NUM_PRICES);
price_base_multiplier[price] = factor; price_base_multiplier[price] = factor;
} }

View File

@ -4,7 +4,7 @@
#define ECONOMY_H #define ECONOMY_H
void ResetPriceBaseMultipliers(void); void ResetPriceBaseMultipliers(void);
void SetPriceBaseMultiplier(int price, byte factor); void SetPriceBaseMultiplier(uint price, byte factor);
typedef struct { typedef struct {
// Maximum possible loan // Maximum possible loan

View File

@ -1070,8 +1070,13 @@ static bool GlobalVarChangeInfo(uint gvid, int numinfo, int prop, byte **bufp, i
case 0x08: { /* Cost base factor */ case 0x08: { /* Cost base factor */
FOR_EACH_OBJECT { FOR_EACH_OBJECT {
byte factor = grf_load_byte(&buf); 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; } break;
default: default: