From c75bf55ff82109094372ff93772c6c9ace3f2a55 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Oct 2022 02:50:16 +0300 Subject: [PATCH 19/19] Fix "unused entry" warnings about worklist padding on savegame See osdn #45671 Signed-off-by: Marko Lindqvist --- server/savegame2.c | 34 ++++++++++++++++++++++++++-------- server/savegame3.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/server/savegame2.c b/server/savegame2.c index a58a9dea75..c33111f064 100644 --- a/server/savegame2.c +++ b/server/savegame2.c @@ -289,8 +289,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, - const char *path, ...); +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); static void sg_special_set(struct tile *ptile, bv_extras *extras, char ch, @@ -340,7 +340,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, @@ -733,8 +734,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; @@ -767,6 +768,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); + } } /**************************************************************************** @@ -3283,6 +3290,7 @@ static void sg_load_player_cities(struct loaddata *loading, { int ncities, i, plrno = player_number(plr); bool tasks_handled; + int wlist_max_length = 0; /* Check status and return if not OK (sg_success FALSE). */ sg_check_ret(); @@ -3301,6 +3309,15 @@ static void sg_load_player_cities(struct loaddata *loading, plr->server.got_first_city = TRUE; } + /* Find longest worklist */ + for (i = 0; i < ncities; i++) { + int wl_length = secfile_lookup_int_default(loading->file, 0, + "player%d.c%d.wl_length", + plrno, i); + + wlist_max_length = MAX(wlist_max_length, wl_length); + } + /* Load all cities of the player. */ for (i = 0; i < ncities; i++) { char buf[32]; @@ -3311,7 +3328,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); @@ -3389,7 +3406,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; @@ -3632,7 +3650,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/savegame3.c b/server/savegame3.c index 209367432c..8aea8bf4e0 100644 --- a/server/savegame3.c +++ b/server/savegame3.c @@ -298,8 +298,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, @@ -951,8 +952,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; @@ -985,6 +986,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); + } } /**************************************************************************** @@ -4511,6 +4518,7 @@ static void sg_load_player_cities(struct loaddata *loading, { int ncities, i, plrno = player_number(plr); bool tasks_handled; + int wlist_max_length = 0; /* Check status and return if not OK (sg_success FALSE). */ sg_check_ret(); @@ -4529,6 +4537,15 @@ static void sg_load_player_cities(struct loaddata *loading, plr->server.got_first_city = TRUE; } + /* Find longest worklist */ + for (i = 0; i < ncities; i++) { + int wl_length = secfile_lookup_int_default(loading->file, 0, + "player%d.c%d.wl_length", + plrno, i); + + wlist_max_length = MAX(wlist_max_length, wl_length); + } + /* Load all cities of the player. */ for (i = 0; i < ncities; i++) { char buf[32]; @@ -4539,7 +4556,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); @@ -4617,7 +4634,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; @@ -4867,7 +4885,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); -- 2.35.1