From add3d75284df1450fec28749ed8c57b9f743dbdb Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 26 Nov 2022 06:23:09 +0200 Subject: [PATCH 29/29] Savegame: Fix "unused entry" warnings about traderoute padding See osdn #45856 Signed-off-by: Marko Lindqvist --- server/savegame/savegame3.c | 58 ++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 9458c629ed..da26e632f1 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -4812,7 +4812,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, int nat_x, nat_y; citizens size; const char *stylename; - int partner = 1; + int partner; int want; sg_warn_ret_val(secfile_lookup_int(loading->file, &nat_x, "%s.x", citystr), @@ -4856,33 +4856,39 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, sp_count += value; } + partner = secfile_lookup_int_default(loading->file, 0, "%s.traderoute0", citystr); for (i = 0; partner != 0; i++) { + struct trade_route *proute = fc_malloc(sizeof(struct trade_route)); + const char *dir; + const char *good_str; + + /* Append to routes list immediately, so the pointer can be found for freeing + * even if we abort */ + trade_route_list_append(pcity->routes, proute); + + proute->partner = partner; + dir = secfile_lookup_str(loading->file, "%s.route_direction%d", citystr, i); + sg_warn_ret_val(dir != NULL, FALSE, + "No traderoute direction found for %s", citystr); + proute->dir = route_direction_by_name(dir, fc_strcasecmp); + sg_warn_ret_val(route_direction_is_valid(proute->dir), FALSE, + "Illegal route direction %s", dir); + good_str = secfile_lookup_str(loading->file, "%s.route_good%d", citystr, i); + sg_warn_ret_val(dir != NULL, FALSE, + "No good found for %s", citystr); + proute->goods = goods_by_rule_name(good_str); + sg_warn_ret_val(proute->goods != NULL, FALSE, + "Illegal good %s", good_str); + + /* Next one */ partner = secfile_lookup_int_default(loading->file, 0, - "%s.traderoute%d", citystr, i); - - if (partner != 0) { - struct trade_route *proute = fc_malloc(sizeof(struct trade_route)); - const char *dir; - const char *good_str; - - /* Append to routes list immediately, so the pointer can be found for freeing - * even if we abort */ - trade_route_list_append(pcity->routes, proute); - - proute->partner = partner; - dir = secfile_lookup_str(loading->file, "%s.route_direction%d", citystr, i); - sg_warn_ret_val(dir != NULL, FALSE, - "No traderoute direction found for %s", citystr); - proute->dir = route_direction_by_name(dir, fc_strcasecmp); - sg_warn_ret_val(route_direction_is_valid(proute->dir), FALSE, - "Illegal route direction %s", dir); - good_str = secfile_lookup_str(loading->file, "%s.route_good%d", citystr, i); - sg_warn_ret_val(dir != NULL, FALSE, - "No good found for %s", citystr); - proute->goods = goods_by_rule_name(good_str); - sg_warn_ret_val(proute->goods != NULL, FALSE, - "Illegal good %s", good_str); - } + "%s.traderoute%d", citystr, i + 1); + } + + for (; i < MAX_TRADE_ROUTES; i++) { + (void) secfile_entry_lookup(loading->file, "%s.traderoute%d", citystr, i); + (void) secfile_entry_lookup(loading->file, "%s.route_direction%d", citystr, i); + (void) secfile_entry_lookup(loading->file, "%s.route_good%d", citystr, i); } sg_warn_ret_val(secfile_lookup_int(loading->file, &pcity->food_stock, -- 2.35.1