summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-08-10 21:41:17 +0000
committerdarkvater <darkvater@openttd.org>2004-08-10 21:41:17 +0000
commit4c6a6ea85cfbd83f5020598ecc43ae4a4c324e9c (patch)
treed5b64abe6a323c3a8a4b91c649e3fbdc4f884da7
parent637a567acb18e22b18e3df329f7f14e14ef3bc88 (diff)
downloadopenttd-4c6a6ea85cfbd83f5020598ecc43ae4a4c324e9c.tar.xz
(svn r18) -Feature Safeguard against invalid values in Patches window. Values will stick to their defined min and max values
-rw-r--r--settings_gui.c58
1 files changed, 46 insertions, 12 deletions
diff --git a/settings_gui.c b/settings_gui.c
index ebb5c38eb..6d5be51c3 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -779,18 +779,52 @@ static int32 ReadPE(const PatchEntry*pe)
return 0;
}
-static void WritePE(const PatchEntry *pe, int32 val)
-{
- switch(pe->type) {
- case PE_BOOL: *(bool*)pe->variable = (bool)val; break;
- case PE_BYTE: *(byte*)pe->variable = (byte)val; break;
- case PE_UINT8: *(uint8*)pe->variable = (uint8)val; break;
- case PE_INT16: *(int16*)pe->variable = (int16)val; break;
- case PE_UINT16: *(uint16*)pe->variable = (uint16)val; break;
- case PE_INT32: *(int32*)pe->variable = val; break;
- default:
- NOT_REACHED();
- }
+static void WritePE(const PatchEntry *pe, int32 val)
+{
+ switch(pe->type) {
+ case PE_BOOL: *(bool*)pe->variable = (bool)val; break;
+ case PE_BYTE: if ((byte)val > (byte)pe->max)
+ *(byte*)pe->variable = (byte)pe->max;
+ else if ((byte)val < (byte)pe->min)
+ *(byte*)pe->variable = (byte)pe->min;
+ else
+ *(byte*)pe->variable = (byte)val;
+ break;
+
+ case PE_UINT8: if ((uint8)val > (uint8)pe->max)
+ *(uint8*)pe->variable = (uint8)pe->max;
+ else if ((uint8)val < (uint8)pe->min)
+ *(uint8*)pe->variable = (uint8)pe->min;
+ else
+ *(uint8*)pe->variable = (uint8)val;
+ break;
+
+ case PE_INT16: if ((int16)val > (int16)pe->max)
+ *(int16*)pe->variable = (int16)pe->max;
+ else if ((int16)val < (int16)pe->min)
+ *(int16*)pe->variable = (int16)pe->min;
+ else
+ *(int16*)pe->variable = (int16)val;
+ break;
+
+ case PE_UINT16: if ((uint16)val > (uint16)pe->max)
+ *(uint16*)pe->variable = (uint16)pe->max;
+ else if ((uint16)val < (uint16)pe->min)
+ *(uint16*)pe->variable = (uint16)pe->min;
+ else
+ *(uint16*)pe->variable = (uint16)val;
+ break;
+
+ case PE_INT32: if ((int32)val > (int32)pe->max)
+ *(int32*)pe->variable = (int32)pe->max;
+ else if ((int32)val < (int32)pe->min)
+ *(int32*)pe->variable = (int32)pe->min;
+ else
+ *(int32*)pe->variable = val;
+ break;
+ default:
+ NOT_REACHED();
+ }
}
static void PatchesSelectionWndProc(Window *w, WindowEvent *e)