From 195435985e1b2549070e54f3575d71662f84f838 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 18 Sep 2023 05:00:07 +0300 Subject: [PATCH 18/18] load_action_range_max(): Avoid duplicate var name detection See osdn #47809 Signed-off-by: Marko Lindqvist --- server/ruleset.c | 72 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/server/ruleset.c b/server/ruleset.c index 6da394d230..ccc03b3797 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -6317,44 +6317,47 @@ static bool load_action_ui_name(struct section_file *file, int act, static bool load_action_range_max(struct rscompat_info *compat, struct section_file *file, action_id act) { - struct entry *pentry; - int max_range; struct action *paction = action_by_number(act); + const char *vname = action_max_range_ruleset_var_name(act); - pentry = secfile_entry_lookup(file, "actions.%s", - action_max_range_ruleset_var_name(act)); + if (vname != NULL) { + struct entry *pentry; + int max_range; + + pentry = secfile_entry_lookup(file, "actions.%s", vname); - if (!pentry) { - const char *compat_name = rscompat_action_max_range_name_S3_1(compat, act); + if (pentry == NULL) { + const char *compat_name = rscompat_action_max_range_name_S3_1(compat, act); - if (compat_name != NULL) { - pentry = secfile_entry_lookup(file, "actions.%s", - compat_name); + if (compat_name != NULL) { + pentry = secfile_entry_lookup(file, "actions.%s", + compat_name); + } } - } - if (!pentry) { - max_range = action_max_range_default(paction->result); - } else { - const char *custom; - - if (entry_type_get(pentry) == ENTRY_INT - && entry_int_get(pentry, &max_range)) { - /* max_range already assigned */ - } else if (entry_type_get(pentry) == ENTRY_STR - && entry_str_get(pentry, &custom) - && !fc_strcasecmp(custom, RS_ACTION_NO_MAX_DISTANCE)) { - max_range = ACTION_DISTANCE_UNLIMITED; + if (pentry == NULL) { + max_range = action_max_range_default(paction->result); } else { - ruleset_error(NULL, LOG_ERROR, "Bad actions.%s", - action_max_range_ruleset_var_name(act)); - action_by_number(act)->max_distance = action_max_range_default(paction->result); + const char *custom; + + if (entry_type_get(pentry) == ENTRY_INT + && entry_int_get(pentry, &max_range)) { + /* max_range already assigned */ + } else if (entry_type_get(pentry) == ENTRY_STR + && entry_str_get(pentry, &custom) + && !fc_strcasecmp(custom, RS_ACTION_NO_MAX_DISTANCE)) { + max_range = ACTION_DISTANCE_UNLIMITED; + } else { + ruleset_error(NULL, LOG_ERROR, "Bad actions.%s", + action_max_range_ruleset_var_name(act)); + action_by_number(act)->max_distance = action_max_range_default(paction->result); - return FALSE; + return FALSE; + } } - } - action_by_number(act)->max_distance = max_range; + action_by_number(act)->max_distance = max_range; + } return TRUE; } @@ -6366,21 +6369,20 @@ static bool load_action_range(struct rscompat_info *compat, struct section_file *file, action_id act) { struct action *paction = action_by_number(act); + const char *vname; - if (action_max_range_ruleset_var_name(act) != NULL) { - /* Max range can be loaded from the ruleset. */ - if (!load_action_range_max(compat, file, act)) { - return FALSE; - } + if (!load_action_range_max(compat, file, act)) { + return FALSE; } - if (action_min_range_ruleset_var_name(act) != NULL) { + vname = action_min_range_ruleset_var_name(act); + if (vname != NULL) { /* Min range can be loaded from the ruleset. */ action_by_number(act)->min_distance = secfile_lookup_int_default(file, action_min_range_default(paction->result), "actions.%s", - action_min_range_ruleset_var_name(act)); + vname); } return TRUE; -- 2.40.1