Skip to content

Commit

Permalink
unit_focus_advance(): Use safe unit list iterate
Browse files Browse the repository at this point in the history
Crashes caused by non-safe iteration reported by bard

See osdn #78170

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
  • Loading branch information
cazfi committed Jun 1, 2024
1 parent 3b69bf5 commit 15e66dc
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions client/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,14 @@ void unit_focus_advance(bool accept_current)
? unit_tile(head_of_units_in_focus())
: NULL);

unit_list_both_iterate(urgent_focus_queue, plink, punit) {
unit_list_iterate_safe(urgent_focus_queue, punit) {
if ((ACTIVITY_IDLE != punit->activity
|| unit_has_orders(punit))
/* This isn't an action decision needed because of an
* ORDER_ACTION_MOVE located in the middle of an order. */
&& !should_ask_server_for_actions(punit)) {
/* We have assigned new orders to this unit since, remove it. */
unit_list_erase(urgent_focus_queue, plink);
unit_list_remove(urgent_focus_queue, punit);
} else if (NULL == focus_tile
|| focus_tile == unit_tile(punit)) {
/* Use the first one found */
Expand All @@ -733,7 +733,7 @@ void unit_focus_advance(bool accept_current)
} else if (NULL == candidate) {
candidate = punit;
}
} unit_list_both_iterate_end;
} unit_list_iterate_safe_end;

if (NULL != candidate) {
unit_list_remove(urgent_focus_queue, candidate);
Expand Down

0 comments on commit 15e66dc

Please sign in to comment.