From d18fa78757cd94de551459ad2d4de8385cdfe146 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 18 Jun 2022 11:16:02 +0300 Subject: [PATCH 23/23] player_distance_to_player(): Fix clang analyze div by zero warning See osdn #44856 Signed-off-by: Marko Lindqvist --- common/aicore/aisupport.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/common/aicore/aisupport.c b/common/aicore/aisupport.c index bcf92e98e6..4195681250 100644 --- a/common/aicore/aisupport.c +++ b/common/aicore/aisupport.c @@ -1,4 +1,4 @@ -/********************************************************************** +/*********************************************************************** Freeciv - Copyright (C) 2003 - The Freeciv Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -69,18 +69,18 @@ struct player *player_leading_spacerace(void) } /********************************************************************** - Calculate average distances to other players. We calculate the + Calculate average distances to other players. We calculate the average distance from all of our cities to the closest enemy city. ***********************************************************************/ int player_distance_to_player(struct player *pplayer, struct player *target) { - int cities = 0; + int cities = city_list_size(pplayer->cities); int dists = 0; if (pplayer == target || !target->is_alive || !pplayer->is_alive - || city_list_size(pplayer->cities) == 0 + || cities == 0 || city_list_size(target->cities) == 0) { return 1; } @@ -97,7 +97,6 @@ int player_distance_to_player(struct player *pplayer, struct player *target) } } city_list_iterate_end; dists += min_dist; - cities++; } city_list_iterate_end; return MAX(dists / cities, 1); -- 2.35.1