From 5bb22a63ab30eac8f2d400d629d5080c63842ae9 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 23 Apr 2022 00:13:22 +0300 Subject: [PATCH 47/47] Fix compiler warnings from --enable-debug + FREECIV_NDEBUG build See osdn #43868 Signed-off-by: Marko Lindqvist --- ai/default/aiferry.c | 3 +-- ai/default/aitools.c | 13 +++++++------ ai/default/daicity.c | 2 ++ client/gui-qt/dialogs.cpp | 2 ++ client/mapctrl_common.c | 2 ++ client/options.c | 14 ++++++++++++-- client/packhand.c | 9 +++++---- common/aicore/cm.c | 7 ++++++- common/aicore/path_finding.c | 2 ++ common/networking/packets.c | 13 ++++++++----- common/unit.c | 9 ++++++--- server/connecthand.c | 9 ++++++--- server/gamehand.c | 2 ++ server/plrhand.c | 7 ++++--- server/savegame/savegame2.c | 11 +++++++++-- server/savegame/savegame3.c | 11 +++++++++-- server/unittools.c | 15 ++++++++++++--- utility/support.c | 5 +++-- 18 files changed, 98 insertions(+), 38 deletions(-) diff --git a/ai/default/aiferry.c b/ai/default/aiferry.c index 447cc9c0da..c0cb070dfb 100644 --- a/ai/default/aiferry.c +++ b/ai/default/aiferry.c @@ -640,12 +640,11 @@ bool dai_amphibious_goto_constrained(struct ai_type *ait, struct pft_amphibious *parameter) { bool alive = TRUE; - struct player *pplayer = unit_owner(passenger); struct pf_map *pfm; struct pf_path *path; int pass_id = passenger->id; - fc_assert_ret_val(is_ai(pplayer), TRUE); + fc_assert_ret_val(is_ai(unit_owner(passenger)), TRUE); fc_assert_ret_val(!unit_has_orders(passenger), TRUE); fc_assert_ret_val(unit_tile(ferry) == unit_tile(passenger), TRUE); diff --git a/ai/default/aitools.c b/ai/default/aitools.c index 7f97b79372..67e2f78446 100644 --- a/ai/default/aitools.c +++ b/ai/default/aitools.c @@ -799,13 +799,14 @@ bool dai_unit_make_homecity(struct unit *punit, struct city *pcity) static void dai_unit_bodyguard_move(struct ai_type *ait, struct unit *bodyguard, struct tile *ptile) { - struct unit *punit; - struct player *pplayer; - fc_assert_ret(bodyguard != NULL); - pplayer = unit_owner(bodyguard); - fc_assert_ret(pplayer != NULL); - punit = aiguard_charge_unit(ait, bodyguard); + fc_assert_ret(unit_owner(bodyguard) != NULL); + +#ifndef FREECIV_NDEBUG + struct unit *punit = +#endif + aiguard_charge_unit(ait, bodyguard); + fc_assert_ret(punit != NULL); CHECK_GUARD(ait, bodyguard); diff --git a/ai/default/daicity.c b/ai/default/daicity.c index 26a82e2237..38c76e2931 100644 --- a/ai/default/daicity.c +++ b/ai/default/daicity.c @@ -1046,7 +1046,9 @@ static void resolve_city_emergency(struct ai_type *ait, struct player *pplayer, log_base(LOG_EMERGENCY, "%s taking over %s square in (%d, %d)", city_name_get(pcity), city_name_get(acity), TILE_XY(atile)); +#ifndef FREECIV_NDEBUG int ax, ay; +#endif fc_assert_action(city_base_to_city_map(&ax, &ay, acity, atile), continue); diff --git a/client/gui-qt/dialogs.cpp b/client/gui-qt/dialogs.cpp index a7bea25c66..b81f26a7c8 100644 --- a/client/gui-qt/dialogs.cpp +++ b/client/gui-qt/dialogs.cpp @@ -4833,7 +4833,9 @@ bool qtg_request_transport(struct unit *pcargo, struct tile *ptile) int tcount; hud_unit_loader *hul; struct unit_list *potential_transports = unit_list_new(); +#ifndef FREECIV_NDEBUG struct unit *best_transport = transporter_for_unit_at(pcargo, ptile); +#endif unit_list_iterate(ptile->units, ptransport) { if (can_unit_transport(ptransport, pcargo) diff --git a/client/mapctrl_common.c b/client/mapctrl_common.c index 4edeb4c511..f4fc1b3890 100644 --- a/client/mapctrl_common.c +++ b/client/mapctrl_common.c @@ -602,7 +602,9 @@ void adjust_workers_button_pressed(int canvas_x, int canvas_y) struct city *pcity = find_city_near_tile(ptile); if (pcity && !cma_is_city_under_agent(pcity, NULL)) { +#ifndef FREECIV_NDEBUG int city_x, city_y; +#endif fc_assert_ret(city_base_to_city_map(&city_x, &city_y, pcity, ptile)); diff --git a/client/options.c b/client/options.c index 3ea518e1c4..4470078eb7 100644 --- a/client/options.c +++ b/client/options.c @@ -6233,17 +6233,27 @@ static void font_changed_callback(struct option *poption) static void mapimg_changed_callback(struct option *poption) { if (mapimg_initialised() && !mapimg_client_define()) { +#ifndef FREECIV_NDEBUG bool success; +#endif log_normal("Error setting the value for %s (%s). Restoring the default " "value.", option_name(poption), mapimg_error()); /* Reset the value to the default value. */ - success = option_reset(poption); +#ifndef FREECIV_NDEBUG + success = +#endif + option_reset(poption); + fc_assert_msg(success, "Failed to reset the option \"%s\".", option_name(poption)); - success = mapimg_client_define(); +#ifndef FREECIV_NDEBUG + success = +#endif + mapimg_client_define(); + fc_assert_msg(success, "Failed to restore mapimg definition for option \"%s\".", option_name(poption)); diff --git a/client/packhand.c b/client/packhand.c index 49c4e318e9..045612efc9 100644 --- a/client/packhand.c +++ b/client/packhand.c @@ -4438,10 +4438,11 @@ void handle_ruleset_nation_sets int i; for (i = 0; i < packet->nsets; i++) { - struct nation_set *pset; - - pset = nation_set_new(packet->names[i], packet->rule_names[i], - packet->descriptions[i]); +#ifndef FREECIV_NDEBUG + struct nation_set *pset = +#endif + nation_set_new(packet->names[i], packet->rule_names[i], + packet->descriptions[i]); fc_assert(NULL != pset); fc_assert(i == nation_set_index(pset)); } diff --git a/common/aicore/cm.c b/common/aicore/cm.c index 133037592f..9d54477fa4 100644 --- a/common/aicore/cm.c +++ b/common/aicore/cm.c @@ -681,7 +681,10 @@ static void apply_solution(struct cm_state *state, const struct partial_solution *soln) { struct city *pcity = state->pcity; - int i, citizen_count = 0, city_radius_sq = city_map_radius_sq_get(pcity); + int i, city_radius_sq = city_map_radius_sq_get(pcity); +#ifndef FREECIV_NDEBUG + int citizen_count = 0; +#endif #ifdef GATHER_TIME_STATS performance.current->apply_count++; @@ -712,7 +715,9 @@ static void apply_solution(struct cm_state *state, /* No citizens of this type. */ continue; } +#ifndef FREECIV_NDEBUG citizen_count += nworkers; +#endif type = tile_type_get(state, i); diff --git a/common/aicore/path_finding.c b/common/aicore/path_finding.c index f908ccf9cb..fb982c9088 100644 --- a/common/aicore/path_finding.c +++ b/common/aicore/path_finding.c @@ -3229,6 +3229,7 @@ struct pf_path *pf_map_path(struct pf_map *pfm, struct tile *ptile) path = pfm->get_path(pfm, ptile); if (path != NULL) { +#ifndef FREECIV_NDEBUG const struct pf_parameter *param = pf_map_parameter(pfm); const struct pf_position *pos = &path->positions[0]; @@ -3236,6 +3237,7 @@ struct pf_path *pf_map_path(struct pf_map *pfm, struct tile *ptile) fc_assert(pos->tile == param->start_tile); fc_assert(pos->moves_left == param->moves_left_initially); fc_assert(pos->fuel_left == param->fuel_left_initially); +#endif /* FREECIV_NDEBUG */ } return path; diff --git a/common/networking/packets.c b/common/networking/packets.c index 01544bf68b..02abf396d2 100644 --- a/common/networking/packets.c +++ b/common/networking/packets.c @@ -116,15 +116,18 @@ static bool conn_compression_flush(struct connection *pconn) { int compression_level = get_compression_level(); uLongf compressed_size = 12 + 1.001 * pconn->compression.queue.size; - int error; Bytef compressed[compressed_size]; bool jumbo; unsigned long compressed_packet_len; - error = compress2(compressed, &compressed_size, - pconn->compression.queue.p, - pconn->compression.queue.size, - compression_level); +#ifndef FREECIV_NDEBUG + int error = +#endif + compress2(compressed, &compressed_size, + pconn->compression.queue.p, + pconn->compression.queue.size, + compression_level); + fc_assert_ret_val(error == Z_OK, FALSE); /* Compression signalling currently assumes a 2-byte packet length; if that diff --git a/common/unit.c b/common/unit.c index bf9c3d6b7c..451052092b 100644 --- a/common/unit.c +++ b/common/unit.c @@ -2276,12 +2276,15 @@ bool unit_transport_unload(struct unit *pcargo) /* Get the transporter; must not be defined on the client! */ ptrans = unit_transport_get(pcargo); if (ptrans) { - bool success; - /* 'pcargo' and 'ptrans' should be on the same tile. */ fc_assert(same_pos(unit_tile(pcargo), unit_tile(ptrans))); + +#ifndef FREECIV_NDEBUG + bool success = +#endif + unit_list_remove(ptrans->transporting, pcargo); + /* It is an error if 'pcargo' can not be removed from the 'ptrans'. */ - success = unit_list_remove(ptrans->transporting, pcargo); fc_assert(success); } diff --git a/server/connecthand.c b/server/connecthand.c index 8da6876311..488fbbec16 100644 --- a/server/connecthand.c +++ b/server/connecthand.c @@ -879,9 +879,12 @@ bool connection_delegate_take(struct connection *pconn, if (!connection_attach(pconn, dplayer, FALSE)) { /* Restore original connection. */ - bool success = connection_attach(pconn, - pconn->server.delegation.playing, - pconn->server.delegation.observer); +#ifndef FREECIV_NDEBUG + bool success = +#endif + connection_attach(pconn, + pconn->server.delegation.playing, + pconn->server.delegation.observer); fc_assert_ret_val(success, FALSE); /* Reset all changes done above. */ diff --git a/server/gamehand.c b/server/gamehand.c index 1550d4e966..56f19892b6 100644 --- a/server/gamehand.c +++ b/server/gamehand.c @@ -691,6 +691,7 @@ void init_new_game(void) /* We need to remove used startpos from the lists. */ i = 0; startpos_list_iterate(flexible_list, plink, psp) { + (void)psp; /* To avoid 'set but unused' compiler warning */ fc_assert(config.startpos[i] == startpos_tile(psp)); if (state.startpos[i] != -1) { startpos_list_erase(flexible_list, plink); @@ -700,6 +701,7 @@ void init_new_game(void) fc_assert(i == config.flexible_startpos_num); if (i < config.usable_startpos_num) { startpos_list_iterate(impossible_list, plink, psp) { + (void)psp; /* To avoid 'set but unused' compiler warning */ fc_assert(config.startpos[i] == startpos_tile(psp)); if (state.startpos[i] != -1) { startpos_list_erase(impossible_list, plink); diff --git a/server/plrhand.c b/server/plrhand.c index 1e1ee25012..7e451d7156 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -2171,9 +2171,10 @@ bool server_player_set_name_full(const struct connection *caller, **************************************************************************/ void server_player_set_name(struct player *pplayer, const char *name) { - bool ret; - - ret = server_player_set_name_full(NULL, pplayer, NULL, name, NULL, 0); +#ifndef FREECIV_NDEBUG + bool ret = +#endif + server_player_set_name_full(NULL, pplayer, NULL, name, NULL, 0); fc_assert(ret); } diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index 7505342b8d..6199d6d662 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -4441,7 +4441,10 @@ static void sg_load_player_units_transport(struct loaddata *loading, fc_assert_action(id_trans == -1 || ptrans != NULL, continue); if (ptrans) { - bool load_success = unit_transport_load(punit, ptrans, TRUE); +#ifndef FREECIV_NDEBUG + bool load_success = +#endif + unit_transport_load(punit, ptrans, TRUE); fc_assert_action(load_success, continue); } @@ -4479,9 +4482,11 @@ static void sg_load_player_attributes(struct loaddata *loading, plr->attribute_block.length = 0; } else if (0 < plr->attribute_block.length) { int part_nr, parts; - size_t actual_length; int quoted_length; char *quoted; +#ifndef FREECIV_NDEBUG + size_t actual_length; +#endif sg_failure_ret( secfile_lookup_int(loading->file, "ed_length, @@ -4516,7 +4521,9 @@ static void sg_load_player_attributes(struct loaddata *loading, (unsigned long) quoted_length, (unsigned long) strlen(quoted)); +#ifndef FREECIV_NDEBUG actual_length = +#endif unquote_block(quoted, plr->attribute_block.data, plr->attribute_block.length); diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index fe07debb37..41446d24a5 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -6256,7 +6256,10 @@ static void sg_load_player_units_transport(struct loaddata *loading, fc_assert_action(id_trans == -1 || ptrans != NULL, continue); if (ptrans) { - bool load_success = unit_transport_load(punit, ptrans, TRUE); +#ifndef FREECIV_NDEBUG + bool load_success = +#endif + unit_transport_load(punit, ptrans, TRUE); fc_assert_action(load_success, continue); } @@ -6544,9 +6547,11 @@ static void sg_load_player_attributes(struct loaddata *loading, plr->attribute_block.length = 0; } else if (0 < plr->attribute_block.length) { int part_nr, parts; - size_t actual_length; int quoted_length; char *quoted; +#ifndef FREECIV_NDEBUG + size_t actual_length; +#endif sg_failure_ret( secfile_lookup_int(loading->file, "ed_length, @@ -6581,7 +6586,9 @@ static void sg_load_player_attributes(struct loaddata *loading, (unsigned long) quoted_length, (unsigned long) strlen(quoted)); +#ifndef FREECIV_NDEBUG actual_length = +#endif unquote_block(quoted, plr->attribute_block.data, plr->attribute_block.length); diff --git a/server/unittools.c b/server/unittools.c index 1ecd7d591e..06039094d9 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -748,16 +748,20 @@ static bool total_activity_done(struct tile *ptile, enum unit_activity act, **************************************************************************/ void notify_unit_experience(struct unit *punit) { - const struct veteran_system *vsystem; const struct veteran_level *vlevel; +#ifndef FREECIV_NDEBUG + const struct veteran_system *vsystem; +#endif if (!punit) { return; } +#ifndef FREECIV_NDEBUG vsystem = utype_veteran_system(unit_type_get(punit)); fc_assert_ret(vsystem != NULL); fc_assert_ret(vsystem->levels > punit->veteran); +#endif /* FREECIV_NDEBUG */ vlevel = utype_veteran_level(unit_type_get(punit), punit->veteran); fc_assert_ret(vlevel != NULL); @@ -1741,7 +1745,7 @@ static void server_remove_unit_full(struct unit *punit, bool transported, /* The unit is doomed. */ punit->server.dying = TRUE; -#ifdef FREECIV_DEBUG +#if defined(FREECIV_DEBUG) && !defined(FREECIV_NDEBUG) unit_list_iterate(ptile->units, pcargo) { fc_assert(unit_transport_get(pcargo) != punit); } unit_list_iterate_end; @@ -3549,7 +3553,9 @@ static struct unit_move_data *unit_move_data(struct unit *punit, get_unit_vision_at(punit, pdesttile, V_INVIS), get_unit_vision_at(punit, pdesttile, V_SUBSURFACE)); struct vision *new_vision; +#ifndef FREECIV_NDEBUG bool success; +#endif if (punit->server.moving) { /* Recursive moving (probably due to a script). */ @@ -3575,7 +3581,10 @@ static struct unit_move_data *unit_move_data(struct unit *punit, /* Remove unit from the source tile. */ fc_assert(unit_tile(punit) == psrctile); - success = unit_list_remove(psrctile->units, punit); +#ifndef FREECIV_NDEBUG + success = +#endif + unit_list_remove(psrctile->units, punit); fc_assert(success); /* Set new tile. */ diff --git a/utility/support.c b/utility/support.c index f30126980c..b003d7380f 100644 --- a/utility/support.c +++ b/utility/support.c @@ -671,7 +671,6 @@ char *fc_strrep_resize(char *str, size_t *len, const char *search, const char *replace) { size_t len_max; - bool success; fc_assert_ret_val(str != NULL, NULL); fc_assert_ret_val(len != NULL, NULL); @@ -687,7 +686,9 @@ char *fc_strrep_resize(char *str, size_t *len, const char *search, str = fc_realloc(str, len_max); } - success = fc_strrep(str, (*len), search, replace); +#ifndef FREECIV_NDEBUG + bool success = fc_strrep(str, (*len), search, replace); +#endif /* should never happen */ fc_assert_ret_val_msg(success, NULL, "Can't replace '%s' by '%s' in '%s'. To small " -- 2.35.1