From fb5945e225761de05ee1922ccfee9d93763d28e6 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 10 Sep 2024 17:43:42 -0500 Subject: [PATCH] Cleanup two divide-by-zero issues from Coverity --- ai/default/aiunit.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ai/default/aiunit.cpp b/ai/default/aiunit.cpp index 00398a11dd..0dd8693259 100644 --- a/ai/default/aiunit.cpp +++ b/ai/default/aiunit.cpp @@ -641,7 +641,8 @@ static void dai_military_bodyguard(struct ai_type *ait, int unit_mv_rate = unit_move_rate(punit); fc_assert_ret_msg(unit_mv_rate, "div by zero"); if (me2goal < me2them - || (me2goal / unit_mv_rate < them2goal / unit_move_rate(aunit) + || (me2goal / unit_mv_rate + < them2goal / std::min(1, unit_move_rate(aunit)) && me2goal / unit_mv_rate < me2them / unit_mv_rate && unit_mv_rate > unit_move_rate(aunit))) { ptile = aunit->goto_tile; @@ -794,7 +795,7 @@ int look_for_charge(struct ai_type *ait, struct player *pplayer, continue; } // Reduce want based on move cost. - def >>= move_cost / (2 * unit_move_rate(punit)); + def >>= move_cost / (2 * std::min(1, unit_move_rate(punit))); if (def > best_def && ai_fuzzy(pplayer, true)) { *acity = pcity; *aunit = nullptr;