(svn r3034) -NewGRF: Improve error checking of setting price bases.
authorpeter1138
Wed, 12 Oct 2005 09:54:29 +0000
changeset 2508 1926793f2977
parent 2507 3689d66cdf42
child 2509 dd48475227dd
(svn r3034) -NewGRF: Improve error checking of setting price bases.
economy.c
economy.h
newgrf.c
--- a/economy.c	Wed Oct 12 09:35:14 2005 +0000
+++ b/economy.c	Wed Oct 12 09:54:29 2005 +0000
@@ -775,7 +775,7 @@
  */
 void ResetPriceBaseMultipliers(void)
 {
-	int i;
+	uint i;
 
 	// 8 means no multiplier.
 	for (i = 0; i < NUM_PRICES; i++)
@@ -789,10 +789,10 @@
  * @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)
--- a/economy.h	Wed Oct 12 09:35:14 2005 +0000
+++ b/economy.h	Wed Oct 12 09:54:29 2005 +0000
@@ -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
--- a/newgrf.c	Wed Oct 12 09:35:14 2005 +0000
+++ b/newgrf.c	Wed Oct 12 09:54:29 2005 +0000
@@ -1070,8 +1070,13 @@
 		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: