From 9a2b764ecbcb43ec6f5380e6ef5645958bc1b313 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 3 Apr 2023 07:17:35 +0300 Subject: [PATCH 18/18] Never accept 'veteran_raise_chance' from 3.1 ruleset Even if loading ruleset in a compatibility mode, refuse 'veteran_raise_chance' when the ruleset loaded isn't 3.0 one to provide compatibility with. Also fixes clang analyzer warning. See osdn #47751 Signed-off-by: Marko Lindqvist --- server/ruleset.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/server/ruleset.c b/server/ruleset.c index 4b486cbb26..64f2dde924 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -194,7 +194,7 @@ static void send_ruleset_team_names(struct conn_list *dest); static bool load_ruleset_veteran(struct section_file *file, const char *path, struct veteran_system **vsystem, char *err, - size_t err_len, bool compat); + size_t err_len, struct rscompat_info *compat); char *script_buffer = NULL; char *parser_buffer = NULL; @@ -1943,7 +1943,7 @@ static bool load_unit_names(struct section_file *file, static bool load_ruleset_veteran(struct section_file *file, const char *path, struct veteran_system **vsystem, char *err, - size_t err_len, bool compat) + size_t err_len, struct rscompat_info *compat) { const char **vlist_name; int *vlist_power, *vlist_raise, *vlist_wraise, *vlist_move; @@ -1964,9 +1964,16 @@ static bool load_ruleset_veteran(struct section_file *file, "%s.veteran_power_fact", path); vlist_raise = secfile_lookup_int_vec(file, &count_raise, "%s.veteran_base_raise_chance", path); - if (vlist_raise == NULL && compat) { - vlist_raise = secfile_lookup_int_vec(file, &count_raise, - "%s.veteran_raise_chance", path); + if (vlist_raise == NULL) { + if (compat->compat_mode && compat->version < RSFORMAT_3_1) { + vlist_raise = secfile_lookup_int_vec(file, &count_raise, + "%s.veteran_raise_chance", path); + } else { + fc_assert(count_raise == 0); /* Should be so from an attempt to + * read veteran_base_raise_chance */ + count_raise = 0; /* ...but clang analyzer doesn't see it, or + * sees something I don't. */ + } } vlist_wraise = secfile_lookup_int_vec(file, &count_wraise, "%s.veteran_work_raise_chance", @@ -2077,7 +2084,7 @@ static bool load_ruleset_units(struct section_file *file, bool ok = TRUE; if (!load_ruleset_veteran(file, "veteran_system", &game.veteran, msg, - sizeof(msg), compat->compat_mode) + sizeof(msg), compat) || game.veteran == NULL) { ruleset_error(NULL, LOG_ERROR, "Error loading the default veteran system: %s", @@ -2225,7 +2232,7 @@ static bool load_ruleset_units(struct section_file *file, } if (!load_ruleset_veteran(file, sec_name, &u->veteran, - msg, sizeof(msg), compat->compat_mode)) { + msg, sizeof(msg), compat)) { ruleset_error(NULL, LOG_ERROR, "Error loading the veteran system: %s", msg); -- 2.39.2