From ebacc7ed0117ec59079508884f5dc85b1e7da421 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 2 Feb 2022 17:50:06 +0200 Subject: [PATCH 32/32] gcc-12: Fix load_ruleset_units() "use after free" warning See osdn #43768 Signed-off-by: Marko Lindqvist --- server/ruleset.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server/ruleset.c b/server/ruleset.c index 16c8eac103..0b5a746fcf 100644 --- a/server/ruleset.c +++ b/server/ruleset.c @@ -2173,7 +2173,7 @@ static bool load_ruleset_units(struct section_file *file, const int i = utype_index(u); struct unit_class *pclass; const char *sec_name = section_name(section_list_get(sec, i)); - const char *string; + const char *str; struct impr_type *impr_req = NULL; /* Read the building build requirement from the old ruleset format @@ -2221,8 +2221,8 @@ static bool load_ruleset_units(struct section_file *file, secfile_lookup_str_default(file, "-", "%s.sound_fight_alt", sec_name)); - if ((string = secfile_lookup_str(file, "%s.graphic", sec_name))) { - sz_strlcpy(u->graphic_str, string); + if ((str = secfile_lookup_str(file, "%s.graphic", sec_name))) { + sz_strlcpy(u->graphic_str, str); } else { ruleset_error(LOG_ERROR, "%s", secfile_error()); ok = FALSE; @@ -2408,17 +2408,16 @@ static bool load_ruleset_units(struct section_file *file, } } unit_class_iterate_end; - u->vlayer = vision_layer_by_name(secfile_lookup_str_default(file, "Main", - "%s.vision_layer", - sec_name), - fc_strcasecmp); + str = secfile_lookup_str_default(file, "Main", "%s.vision_layer", + sec_name); + u->vlayer = vision_layer_by_name(str, fc_strcasecmp); if (!vision_layer_is_valid(u->vlayer)) { ruleset_error(LOG_ERROR, "\"%s\" unit_type \"%s\":" "has unknown vision layer %s.", filename, utype_rule_name(u), - slist[j]); + str); ok = FALSE; break; } -- 2.34.1