Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup two divide-by-zero issues from Coverity #2386

Merged
merged 3 commits into from
Sep 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ai/default/aiunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
jwrober marked this conversation as resolved.
Show resolved Hide resolved
ptile = aunit->goto_tile;
Expand Down Expand Up @@ -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;
Expand Down
Loading