From 6d70a05a6517c1be76f32659aa4c64270cf25745 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Mon, 18 Sep 2023 04:54:16 +0300 Subject: [PATCH 26/26] load_action_range_max(): Avoid duplicate var name detection See osdn #47809 Signed-off-by: Marko Lindqvist --- server/ruleset.c | 60 +++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/server/ruleset.c b/server/ruleset.c index ff91834534..4e61c4e4e2 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -6272,35 +6272,38 @@ static bool load_action_ui_name(struct section_file *file, int act, **************************************************************************/ static bool load_action_range_max(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; - 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; + pentry = secfile_entry_lookup(file, "actions.%s", vname); + + 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; } @@ -6311,21 +6314,20 @@ static bool load_action_range_max(struct section_file *file, action_id act) static bool load_action_range(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(file, act)) { - return FALSE; - } + if (!load_action_range_max(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