From 3643c0231c8b377e45f2297f4219943c71a4498e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 15 May 2022 07:29:38 +0300 Subject: [PATCH 40/41] local_ave_elevation(): Fix clang analyzer div by zero warning See osdn #44569 Signed-off-by: Marko Lindqvist --- server/generator/fracture_map.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/generator/fracture_map.c b/server/generator/fracture_map.c index 52610db84c..9d7e07d8d0 100644 --- a/server/generator/fracture_map.c +++ b/server/generator/fracture_map.c @@ -260,8 +260,8 @@ static void fmfill(int x, int y, int c, int r) } /**********************************************************************//** - Determine the local average elevation. Used to determine where hills - and mountains are. + Determine the local average elevation. Used to determine where hills + and mountains are. **************************************************************************/ static int local_ave_elevation(struct tile *ptile) { @@ -273,7 +273,10 @@ static int local_ave_elevation(struct tile *ptile) ele = ele + hmap(tile2); n++; } square_iterate_end; - ele /= n; + + if (ele > 0) { /* Avoids div by zero, as means also that n > 0 */ + ele /= n; + } return ele; } -- 2.35.1