From e96b4beece4a7a923fd1537587e72916202e7ab7 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Oct 2022 02:39:09 +0300 Subject: [PATCH 34/34] Fix "unused entry" warnings about worklist padding on savegame See osdn #45671 Signed-off-by: Marko Lindqvist --- server/savegame/savecompat.c | 58 ++++++++++++++++++++++++++++++++++++ server/savegame/savegame2.c | 27 ++++++++++++----- server/savegame/savegame3.c | 31 ++++++++++++++----- 3 files changed, 101 insertions(+), 15 deletions(-) diff --git a/server/savegame/savecompat.c b/server/savegame/savecompat.c index 2527ddba9e..183cc9ae8d 100644 --- a/server/savegame/savecompat.c +++ b/server/savegame/savecompat.c @@ -2140,6 +2140,35 @@ static void compat_load_030200(struct loaddata *loading, "savefile.diplstate_type_vector,%d", i); } } + + /* Add wl_max_length entries for players */ + { + player_slots_iterate(pslot) { + int plrno = player_slot_index(pslot); + int ncities; + int cnro; + int wlist_max_length = 0; + + if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) { + continue; + } + + ncities = secfile_lookup_int_default(loading->file, 0, + "player%d.ncities", plrno); + + for (cnro = 0; cnro < ncities; cnro++) { + int wl_length = secfile_lookup_int_default(loading->file, 0, + "player%d.c%d.wl_length", + plrno, cnro); + + wlist_max_length = MAX(wlist_max_length, wl_length); + } + + secfile_insert_int(loading->file, wlist_max_length, + "player%d.wl_max_length", plrno); + + } player_slots_iterate_end; + } } /************************************************************************//** @@ -2755,6 +2784,35 @@ static void compat_load_dev(struct loaddata *loading) } (void) secfile_entry_lookup(loading->file, "game.hardcoded_counters"); + + /* Add wl_max_length entries for players */ + { + player_slots_iterate(pslot) { + int plrno = player_slot_index(pslot); + int ncities; + int cnro; + int wlist_max_length = 0; + + if (secfile_section_lookup(loading->file, "player%d", plrno) == NULL) { + continue; + } + + ncities = secfile_lookup_int_default(loading->file, 0, + "player%d.ncities", plrno); + + for (cnro = 0; cnro < ncities; cnro++) { + int wl_length = secfile_lookup_int_default(loading->file, 0, + "player%d.c%d.wl_length", + plrno, cnro); + + wlist_max_length = MAX(wlist_max_length, wl_length); + } + + secfile_insert_int(loading->file, wlist_max_length, + "player%d.wl_max_length", plrno); + + } player_slots_iterate_end; + } } /* Version < 3.1.93 */ #endif /* FREECIV_DEV_SAVE_COMPAT_3_2 */ diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index db563db3cf..3dc1710b31 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -292,7 +292,8 @@ static char activity2char(enum unit_activity activity); static enum unit_activity char2activity(char activity); static int unquote_block(const char *const quoted_, void *dest, int dest_length); -static void worklist_load(struct section_file *file, struct worklist *pwl, +static void worklist_load(struct section_file *file, int wlist_max_length, + struct worklist *pwl, const char *path, ...); static void unit_ordering_apply(void); static void sg_extras_set(bv_extras *extras, char ch, struct extra_type **idx); @@ -342,7 +343,8 @@ static void sg_load_player_main(struct loaddata *loading, static void sg_load_player_cities(struct loaddata *loading, struct player *plr); static bool sg_load_player_city(struct loaddata *loading, struct player *plr, - struct city *pcity, const char *citystr); + struct city *pcity, const char *citystr, + int wlist_max_length); static void sg_load_player_city_citizens(struct loaddata *loading, struct player *plr, struct city *pcity, @@ -751,8 +753,8 @@ static int unquote_block(const char *const quoted_, void *dest, Load the worklist elements specified by path to the worklist pointed to by 'pwl'. 'pwl' should be a pointer to an existing worklist. ****************************************************************************/ -static void worklist_load(struct section_file *file, struct worklist *pwl, - const char *path, ...) +static void worklist_load(struct section_file *file, int wlist_max_length, + struct worklist *pwl, const char *path, ...) { int i; const char *kind; @@ -785,6 +787,12 @@ static void worklist_load(struct section_file *file, struct worklist *pwl, break; } } + + /* Padding entries */ + for (; i < wlist_max_length; i++) { + (void) secfile_entry_lookup(file, "%s.wl_kind%d", path_str, i); + (void) secfile_entry_lookup(file, "%s.wl_value%d", path_str, i); + } } /************************************************************************//** @@ -3317,6 +3325,7 @@ static void sg_load_player_cities(struct loaddata *loading, { int ncities, i, plrno = player_number(plr); bool tasks_handled; + int wlist_max_length; /* Check status and return if not OK (sg_success FALSE). */ sg_check_ret(); @@ -3335,6 +3344,9 @@ static void sg_load_player_cities(struct loaddata *loading, plr->server.got_first_city = TRUE; } + wlist_max_length = secfile_lookup_int_default(loading->file, 0, + "player%d.wl_max_length", plrno); + /* Load all cities of the player. */ for (i = 0; i < ncities; i++) { char buf[32]; @@ -3345,7 +3357,7 @@ static void sg_load_player_cities(struct loaddata *loading, /* Create a dummy city. */ pcity = create_city_virtual(plr, NULL, buf); adv_city_alloc(pcity); - if (!sg_load_player_city(loading, plr, pcity, buf)) { + if (!sg_load_player_city(loading, plr, pcity, buf, wlist_max_length)) { adv_city_free(pcity); destroy_city_virtual(pcity); sg_failure_ret(FALSE, "Error loading city %d of player %d.", i, plrno); @@ -3423,7 +3435,8 @@ static void sg_load_player_cities(struct loaddata *loading, Load data for one city. ****************************************************************************/ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, - struct city *pcity, const char *citystr) + struct city *pcity, const char *citystr, + int wlist_max_length) { struct player *past; const char *kind, *name, *str; @@ -3667,7 +3680,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, } /* worklist_init() done in create_city_virtual() */ - worklist_load(loading->file, &pcity->worklist, "%s", citystr); + worklist_load(loading->file, wlist_max_length, &pcity->worklist, "%s", citystr); /* Load city options. */ BV_CLR_ALL(pcity->city_options); diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index 958ca96952..dd662759e2 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -297,8 +297,8 @@ static enum unit_activity char2activity(char activity); static char *quote_block(const void *const data, int length); static int unquote_block(const char *const quoted_, void *dest, int dest_length); -static void worklist_load(struct section_file *file, struct worklist *pwl, - const char *path, ...); +static void worklist_load(struct section_file *file, int wlist_max_length, + struct worklist *pwl, const char *path, ...); static void worklist_save(struct section_file *file, const struct worklist *pwl, int max_length, const char *path, ...); @@ -363,7 +363,8 @@ static void sg_load_player_main(struct loaddata *loading, static void sg_load_player_cities(struct loaddata *loading, struct player *plr); static bool sg_load_player_city(struct loaddata *loading, struct player *plr, - struct city *pcity, const char *citystr); + struct city *pcity, const char *citystr, + int wlist_max_length); static void sg_load_player_city_citizens(struct loaddata *loading, struct player *plr, struct city *pcity, @@ -949,8 +950,8 @@ static int unquote_block(const char *const quoted_, void *dest, Load the worklist elements specified by path to the worklist pointed to by 'pwl'. 'pwl' should be a pointer to an existing worklist. ****************************************************************************/ -static void worklist_load(struct section_file *file, struct worklist *pwl, - const char *path, ...) +static void worklist_load(struct section_file *file, int wlist_max_length, + struct worklist *pwl, const char *path, ...) { int i; const char *kind; @@ -983,6 +984,12 @@ static void worklist_load(struct section_file *file, struct worklist *pwl, break; } } + + /* Padding entries */ + for (; i < wlist_max_length; i++) { + (void) secfile_entry_lookup(file, "%s.wl_kind%d", path_str, i); + (void) secfile_entry_lookup(file, "%s.wl_value%d", path_str, i); + } } /************************************************************************//** @@ -4795,6 +4802,7 @@ static void sg_load_player_cities(struct loaddata *loading, { int ncities, i, plrno = player_number(plr); bool tasks_handled; + int wlist_max_length; /* Check status and return if not OK (sg_success FALSE). */ sg_check_ret(); @@ -4813,6 +4821,9 @@ static void sg_load_player_cities(struct loaddata *loading, plr->server.got_first_city = TRUE; } + wlist_max_length = secfile_lookup_int_default(loading->file, 0, + "player%d.wl_max_length", plrno); + /* Load all cities of the player. */ for (i = 0; i < ncities; i++) { char buf[32]; @@ -4823,7 +4834,7 @@ static void sg_load_player_cities(struct loaddata *loading, /* Create a dummy city. */ pcity = create_city_virtual(plr, NULL, buf); adv_city_alloc(pcity); - if (!sg_load_player_city(loading, plr, pcity, buf)) { + if (!sg_load_player_city(loading, plr, pcity, buf, wlist_max_length)) { adv_city_free(pcity); destroy_city_virtual(pcity); sg_failure_ret(FALSE, "Error loading city %d of player %d.", i, plrno); @@ -4907,7 +4918,8 @@ static void sg_load_player_cities(struct loaddata *loading, Load data for one city. sg_save_player_city() is not defined. ****************************************************************************/ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, - struct city *pcity, const char *citystr) + struct city *pcity, const char *citystr, + int wlist_max_length) { struct player *past; const char *kind, *name, *str; @@ -5169,7 +5181,7 @@ static bool sg_load_player_city(struct loaddata *loading, struct player *plr, } /* worklist_init() done in create_city_virtual() */ - worklist_load(loading->file, &pcity->worklist, "%s", citystr); + worklist_load(loading->file, wlist_max_length, &pcity->worklist, "%s", citystr); /* Load city options. */ BV_CLR_ALL(pcity->city_options); @@ -5420,6 +5432,9 @@ static void sg_save_player_cities(struct savedata *saving, } } city_list_iterate_end; + secfile_insert_int(saving->file, wlist_max_length, + "player%d.wl_max_length", plrno); + city_list_iterate(plr->cities, pcity) { struct tile *pcenter = city_tile(pcity); char impr_buf[B_LAST + 1]; -- 2.35.1