From aaa270158c01e7c3820198cd53ffae13485af9ef Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Fri, 8 Apr 2022 22:21:58 +0300 Subject: [PATCH 09/19] Asserts: Never compare boolean value to exact value of TRUE or FALSE This handles such cases inside asserts only. See osdn #44130 Signed-off-by: Marko Lindqvist --- client/goto.c | 2 +- client/options.c | 4 ++-- common/aicore/path_finding.c | 21 ++++++++++++--------- common/fc_interface.c | 2 +- common/server_settings.c | 2 +- server/connecthand.c | 4 ++-- server/plrhand.c | 3 ++- server/savegame2.c | 2 +- server/savegame3.c | 2 +- server/settings.c | 8 ++++---- server/srv_main.c | 2 +- server/unittools.c | 4 ++-- utility/inputfile.c | 8 ++++---- utility/support.c | 2 +- 14 files changed, 35 insertions(+), 31 deletions(-) diff --git a/client/goto.c b/client/goto.c index ff4cd735ee..5aea895cd9 100644 --- a/client/goto.c +++ b/client/goto.c @@ -894,7 +894,7 @@ static void goto_fill_parameter_base(struct pf_parameter *parameter, fc_assert(parameter->get_TB == NULL); fc_assert(parameter->get_MC != NULL); fc_assert(parameter->start_tile == unit_tile(punit)); - fc_assert(parameter->omniscience == FALSE); + fc_assert(!parameter->omniscience); parameter->get_EC = get_EC; if (utype_acts_hostile(unit_type_get(punit))) { diff --git a/client/options.c b/client/options.c index f71e170026..161af44247 100644 --- a/client/options.c +++ b/client/options.c @@ -6256,11 +6256,11 @@ static void mapimg_changed_callback(struct option *poption) /* Reset the value to the default value. */ success = option_reset(poption); - fc_assert_msg(success == TRUE, + fc_assert_msg(success, "Failed to reset the option \"%s\".", option_name(poption)); success = mapimg_client_define(); - fc_assert_msg(success == TRUE, + fc_assert_msg(success, "Failed to restore mapimg definition for option \"%s\".", option_name(poption)); } diff --git a/common/aicore/path_finding.c b/common/aicore/path_finding.c index ef54bcc2cb..8c283eeba7 100644 --- a/common/aicore/path_finding.c +++ b/common/aicore/path_finding.c @@ -893,8 +893,8 @@ static struct pf_map *pf_normal_map_new(const struct pf_parameter *parameter) if (NULL == params->get_costs) { if (!pf_normal_node_init(pfnm, node, params->start_tile, PF_MS_NONE)) { /* Always fails. */ - fc_assert(TRUE == pf_normal_node_init(pfnm, node, params->start_tile, - PF_MS_NONE)); + fc_assert(pf_normal_node_init(pfnm, node, params->start_tile, + PF_MS_NONE)); } if (NULL != params->transported_by_initially) { @@ -1894,8 +1894,8 @@ static struct pf_map *pf_danger_map_new(const struct pf_parameter *parameter) node = pfdm->lattice + tile_index(params->start_tile); if (!pf_danger_node_init(pfdm, node, params->start_tile, PF_MS_NONE)) { /* Always fails. */ - fc_assert(TRUE == pf_danger_node_init(pfdm, node, params->start_tile, - PF_MS_NONE)); + fc_assert(pf_danger_node_init(pfdm, node, params->start_tile, + PF_MS_NONE)); } /* NB: do not handle params->transported_by_initially because we want to @@ -2905,9 +2905,12 @@ static bool pf_fuel_map_iterate(struct pf_map *pfm) #endif } else { #ifdef PF_DEBUG - bool success = map_index_pq_remove(pffm->queue, &tindex); +#ifndef FREECIV_NDEBUG + bool success = +#endif + map_index_pq_remove(pffm->queue, &tindex); - fc_assert(TRUE == success); + fc_assert(success); #else map_index_pq_remove(pffm->queue, &tindex); #endif @@ -3117,8 +3120,8 @@ static struct pf_map *pf_fuel_map_new(const struct pf_parameter *parameter) node = pffm->lattice + tile_index(params->start_tile); if (!pf_fuel_node_init(pffm, node, params->start_tile, PF_MS_NONE)) { /* Always fails. */ - fc_assert(TRUE == pf_fuel_node_init(pffm, node, params->start_tile, - PF_MS_NONE)); + fc_assert(pf_fuel_node_init(pffm, node, params->start_tile, + PF_MS_NONE)); } /* NB: do not handle params->transported_by_initially because we want to @@ -3618,7 +3621,7 @@ static bool pf_pos_hash_cmp(const struct pf_parameter *parameter1, if (!parameter1->omniscience) { #ifdef PF_DEBUG - fc_assert(parameter2->omniscience == FALSE); + fc_assert(!parameter2->omniscience); #endif if (parameter1->utype->unknown_move_cost != parameter2->utype->unknown_move_cost) { diff --git a/common/fc_interface.c b/common/fc_interface.c index b7a07d198b..e02835970d 100644 --- a/common/fc_interface.c +++ b/common/fc_interface.c @@ -42,7 +42,7 @@ bool fc_funcs_defined = FALSE; **************************************************************************/ struct functions *fc_interface_funcs(void) { - fc_assert_exit(fc_funcs_defined == FALSE); + fc_assert_exit(!fc_funcs_defined); return &fc_functions; } diff --git a/common/server_settings.c b/common/server_settings.c index b206b6bb77..b6138f4351 100644 --- a/common/server_settings.c +++ b/common/server_settings.c @@ -108,7 +108,7 @@ ssetv ssetv_from_values(server_setting_id setting, int value) /* Only Boolean and TRUE can be supported unless setting value encoding * is implemented. */ if (value != TRUE) { - fc_assert(value == TRUE); + fc_assert(value); return SSETV_NONE; } diff --git a/server/connecthand.c b/server/connecthand.c index 87e3a5cbbe..726131a453 100644 --- a/server/connecthand.c +++ b/server/connecthand.c @@ -474,7 +474,7 @@ void lost_connection_to_client(struct connection *pconn) { const char *desc = conn_description(pconn); - fc_assert_ret(TRUE == pconn->server.is_closing); + fc_assert_ret(pconn->server.is_closing); log_normal(_("Lost connection: %s."), desc); @@ -823,7 +823,7 @@ void connection_detach(struct connection *pconn, bool remove_unused_player) bool connection_delegate_take(struct connection *pconn, struct player *dplayer) { - fc_assert_ret_val(pconn->server.delegation.status == FALSE, FALSE); + fc_assert_ret_val(!pconn->server.delegation.status, FALSE); /* Save the original player of this connection and the original username of * the player. */ diff --git a/server/plrhand.c b/server/plrhand.c index 5170c597bb..ae960bcf01 100644 --- a/server/plrhand.c +++ b/server/plrhand.c @@ -2018,7 +2018,8 @@ 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); - fc_assert(TRUE == ret); + + fc_assert(ret); } /************************************************************************** diff --git a/server/savegame2.c b/server/savegame2.c index 398d23f062..a31103ad41 100644 --- a/server/savegame2.c +++ b/server/savegame2.c @@ -4385,7 +4385,7 @@ static void sg_load_player_units_transport(struct loaddata *loading, if (ptrans) { bool load_success = unit_transport_load(punit, ptrans, TRUE); - fc_assert_action(load_success == TRUE, continue); + fc_assert_action(load_success, continue); } } } diff --git a/server/savegame3.c b/server/savegame3.c index b71180c1dd..8fc3a4a8e3 100644 --- a/server/savegame3.c +++ b/server/savegame3.c @@ -5692,7 +5692,7 @@ static void sg_load_player_units_transport(struct loaddata *loading, if (ptrans) { bool load_success = unit_transport_load(punit, ptrans, TRUE); - fc_assert_action(load_success == TRUE, continue); + fc_assert_action(load_success, continue); } } } diff --git a/server/settings.c b/server/settings.c index a90b4d6262..0623687c7a 100644 --- a/server/settings.c +++ b/server/settings.c @@ -5100,7 +5100,7 @@ static void settings_list_init(void) struct setting *pset; int i; - fc_assert_ret(setting_sorted.init == FALSE); + fc_assert_ret(!setting_sorted.init); /* Do it for all values of enum sset_level. */ for (i = 0; i < OLEVELS_NUM; i++) { @@ -5158,7 +5158,7 @@ void settings_list_update(void) struct setting *pset; int i; - fc_assert_ret(setting_sorted.init == TRUE); + fc_assert_ret(setting_sorted.init); /* Clear the lists for changed and locked values. */ setting_list_clear(setting_sorted.level[SSET_CHANGED]); @@ -5197,7 +5197,7 @@ int settings_list_cmp(const struct setting *const *ppset1, *****************************************************************************/ struct setting_list *settings_list_get(enum sset_level level) { - fc_assert_ret_val(setting_sorted.init == TRUE, NULL); + fc_assert_ret_val(setting_sorted.init, NULL); fc_assert_ret_val(setting_sorted.level[level] != NULL, NULL); fc_assert_ret_val(sset_level_is_valid(level), NULL); @@ -5211,7 +5211,7 @@ static void settings_list_free(void) { int i; - fc_assert_ret(setting_sorted.init == TRUE); + fc_assert_ret(setting_sorted.init); /* Free the lists. */ for (i = 0; i < OLEVELS_NUM; i++) { diff --git a/server/srv_main.c b/server/srv_main.c index 2d8f369982..899b205ad0 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -3151,7 +3151,7 @@ static void srv_ready(void) fc_assert_action(pset != NULL, continue); success = setting_enum_set(pset, mapgen_settings[set].value, NULL, error, sizeof(error)); - fc_assert_msg(success == TRUE, + fc_assert_msg(success, "Failed to restore '%s': %s", mapgen_settings[set].name, error); diff --git a/server/unittools.c b/server/unittools.c index a99d16958c..d4adc7541b 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -3525,7 +3525,7 @@ 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); - fc_assert(success == TRUE); + fc_assert(success); /* Set new tile. */ unit_tile_set(punit, pdesttile); @@ -4475,7 +4475,7 @@ bool execute_orders(struct unit *punit, const bool fresh) } if (last_order) { - fc_assert(punit->has_orders == FALSE); + fc_assert(!punit->has_orders); log_debug(" stopping because orders are complete"); return TRUE; } diff --git a/utility/inputfile.c b/utility/inputfile.c index 1b11dee713..869c9c700c 100644 --- a/utility/inputfile.c +++ b/utility/inputfile.c @@ -184,10 +184,10 @@ static bool inf_sanity_check(struct inputfile *inf) fc_assert_ret_val(NULL != inf, FALSE); fc_assert_ret_val(INF_MAGIC == inf->magic, FALSE); fc_assert_ret_val(NULL != inf->fp, FALSE); - fc_assert_ret_val(FALSE == inf->at_eof - || TRUE == inf->at_eof, FALSE); - fc_assert_ret_val(FALSE == inf->in_string - || TRUE == inf->in_string, FALSE); + fc_assert_ret_val(!inf->at_eof + || inf->at_eof, FALSE); + fc_assert_ret_val(!inf->in_string + || inf->in_string, FALSE); #ifdef FREECIV_DEBUG fc_assert_ret_val(0 <= inf->string_start_line, FALSE); diff --git a/utility/support.c b/utility/support.c index 331a4682bd..970e82af99 100644 --- a/utility/support.c +++ b/utility/support.c @@ -689,7 +689,7 @@ char *fc_strrep_resize(char *str, size_t *len, const char *search, success = fc_strrep(str, (*len), search, replace); /* should never happen */ - fc_assert_ret_val_msg(success == TRUE, NULL, + fc_assert_ret_val_msg(success, NULL, "Can't replace '%s' by '%s' in '%s'. To small " "size after reallocation: %lu.", search, replace, str, (long unsigned int)*len); -- 2.35.1