summaryrefslogtreecommitdiff
path: root/src/table
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-03-01 13:12:17 +0100
committerPatric Stout <github@truebrain.nl>2021-03-01 23:17:47 +0100
commit74aa934441351334e40d8963900b8a2fbc9bc9cd (patch)
tree1257efebb69111b35c5026d59c0504088faff0d8 /src/table
parentd7a70c67bacef7453ae56e9136c9c16e4b19c314 (diff)
downloadopenttd-74aa934441351334e40d8963900b8a2fbc9bc9cd.tar.xz
Codechange: validate that "max" value of settings fit in their storage
This is an easy mistake to make, so protect us against making such mistakes, by validating it doesn't happen.
Diffstat (limited to 'src/table')
-rw-r--r--src/table/company_settings.ini3
-rw-r--r--src/table/currency_settings.ini3
-rw-r--r--src/table/gameopt_settings.ini7
-rw-r--r--src/table/misc_settings.ini4
-rw-r--r--src/table/settings.ini8
-rw-r--r--src/table/win32_settings.ini3
-rw-r--r--src/table/window_settings.ini3
7 files changed, 31 insertions, 0 deletions
diff --git a/src/table/company_settings.ini b/src/table/company_settings.ini
index e685ff6dc..eea2371fc 100644
--- a/src/table/company_settings.ini
+++ b/src/table/company_settings.ini
@@ -20,6 +20,9 @@ SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def,
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_END = SDT_END()
+[validation]
+SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+
[defaults]
flags = 0
guiflags = SGF_PER_COMPANY
diff --git a/src/table/currency_settings.ini b/src/table/currency_settings.ini
index 7ff879964..c242c83a8 100644
--- a/src/table/currency_settings.ini
+++ b/src/table/currency_settings.ini
@@ -14,6 +14,9 @@ SDT_CHR = SDT_CHR($base, $var, $flags, $guiflags, $def,
SDT_STR = SDT_STR($base, $var, $type, $flags, $guiflags, $def, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_END = SDT_END()
+[validation]
+SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+
[defaults]
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NONE
diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini
index b85e11d9c..c4140f428 100644
--- a/src/table/gameopt_settings.ini
+++ b/src/table/gameopt_settings.ini
@@ -46,6 +46,13 @@ SDT_OMANY = SDT_OMANY($base, $var, $type, $flags, $guiflags, $def, $ma
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_END = SDT_END()
+[validation]
+SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDT_OMANY = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+
[defaults]
flags = 0
guiflags = SGF_NONE
diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini
index 3add5148f..9d2f76cc0 100644
--- a/src/table/misc_settings.ini
+++ b/src/table/misc_settings.ini
@@ -26,6 +26,10 @@ SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def,
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDTG_END = SDTG_END()
+[validation]
+SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+
[defaults]
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NONE
diff --git a/src/table/settings.ini b/src/table/settings.ini
index dd0ecfee5..b48ac6cd6 100644
--- a/src/table/settings.ini
+++ b/src/table/settings.ini
@@ -77,6 +77,14 @@ SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min,
SDT_NULL = SDT_NULL($length, $from, $to),
SDT_END = SDT_END()
+[validation]
+SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDTG_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDTC_OMANY = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDTC_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+SDT_OMANY = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+
[defaults]
flags = 0
guiflags = SGF_NONE
diff --git a/src/table/win32_settings.ini b/src/table/win32_settings.ini
index 406e8dd8f..c3cc45014 100644
--- a/src/table/win32_settings.ini
+++ b/src/table/win32_settings.ini
@@ -18,6 +18,9 @@ SDTG_BOOL = SDTG_BOOL($name, $flags, $guiflags, $var, $def,
SDTG_VAR = SDTG_VAR($name, $type, $flags, $guiflags, $var, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDTG_END = SDTG_END()
+[validation]
+SDTG_VAR = static_assert($max <= MAX_$type, "Maximum value for $var exceeds storage size");
+
[defaults]
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC
guiflags = SGF_NONE
diff --git a/src/table/window_settings.ini b/src/table/window_settings.ini
index e336d6447..fb252076c 100644
--- a/src/table/window_settings.ini
+++ b/src/table/window_settings.ini
@@ -14,6 +14,9 @@ SDT_BOOL = SDT_BOOL($base, $var, $flags, $guiflags, $def,
SDT_VAR = SDT_VAR($base, $var, $type, $flags, $guiflags, $def, $min, $max, $interval, $str, $strhelp, $strval, $proc, $from, $to, $cat, $extra, $startup),
SDT_END = SDT_END()
+[validation]
+SDT_VAR = static_assert($max <= MAX_$type, "Maximum value for $base.$var exceeds storage size");
+
[defaults]
base = WindowDesc
flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC