From 4c93228ea8910cacfc343ca33acf635d8a13b7c2 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 8 Oct 2022 02:50:16 +0300 Subject: [PATCH 27/27] Fix "unused entry" warnings about worklist padding on savegame See osdn #45671 Signed-off-by: Marko Lindqvist --- server/savegame/savegame2.c | 34 ++++++++++++++++++++++++++-------- server/savegame/savegame3.c | 34 ++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index 671624a28f..fa9553a673 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -292,8 +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, - 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, @@ -342,7 +342,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, @@ -745,8 +746,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; @@ -779,6 +780,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); + } } /************************************************************************//** @@ -3295,6 +3302,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(); @@ -3313,6 +3321,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]; @@ -3323,7 +3340,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); @@ -3401,7 +3418,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; @@ -3644,7 +3662,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 b4c16eded8..6a3e47b454 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -295,8 +295,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, ...); @@ -358,7 +358,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, @@ -934,8 +935,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; @@ -968,6 +969,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); + } } /************************************************************************//** @@ -4673,6 +4680,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(); @@ -4691,6 +4699,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]; @@ -4701,7 +4718,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); @@ -4785,7 +4802,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; @@ -5044,7 +5062,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