Skip to content

Commit

Permalink
Server: Backport 0023-bounce_unit-Fix-unit-list-corruption-on-iterati…
Browse files Browse the repository at this point in the history
…on.patch

Signed-off-by: Marko Lindqvist <[email protected]>
  • Loading branch information
cazfi committed Jul 21, 2023
1 parent 2212460 commit 49eed3f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions freeciv/apply_patches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
# 0022-occupy_move-Fix-crash-if-unit-died-on-autoperformers.patch
# Fix crash when server side autoattack enabled
# osdn #48300
# 0023-bounce_unit-Fix-unit-list-corruption-on-iteration.patch
# Memory handling fix
# osdn #48392

# Not in the upstream Freeciv server
# ----------------------------------
Expand Down Expand Up @@ -59,6 +62,7 @@ declare -a PATCHLIST=(
"backports/0014-Meson-Fix-configure-on-FORTIFY_SOURCE-envs"
"backports/0025-Don-t-notify-unrelated-players-about-their-governmen"
"backports/0022-occupy_move-Fix-crash-if-unit-died-on-autoperformers"
"backports/0023-bounce_unit-Fix-unit-list-corruption-on-iteration"
"meson_webperimental"
"metachange"
"text_fixes"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
From f5e07871ae254926e70110fff36be57729379ff8 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <[email protected]>
Date: Wed, 19 Jul 2023 22:33:49 +0300
Subject: [PATCH 23/23] bounce_unit(): Fix unit list corruption on iteration

Transported units were bounced away from transported list,
within normal unit list iteration.
Turn that to a safe-iterator.

See osdn #48392

Signed-off-by: Marko Lindqvist <[email protected]>
---
server/unittools.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/server/unittools.c b/server/unittools.c
index 4dbcb39b5e..4024c4a194 100644
--- a/server/unittools.c
+++ b/server/unittools.c
@@ -1300,9 +1300,9 @@ void bounce_unit(struct unit *punit, bool verbose)
struct unit_list *pcargo_units;

pcargo_units = unit_transport_cargo(punit);
- unit_list_iterate(pcargo_units, pcargo) {
+ unit_list_iterate_safe(pcargo_units, pcargo) {
bounce_unit(pcargo, verbose);
- } unit_list_iterate_end;
+ } unit_list_iterate_safe_end;
}

if (verbose) {
@@ -1311,10 +1311,10 @@ void bounce_unit(struct unit *punit, bool verbose)
_("Disbanded your %s."),
unit_tile_link(punit));
}
+
wipe_unit(punit, ULR_STACK_CONFLICT, NULL);
}

-
/**********************************************************************//**
Throw pplayer's units from non-allied cities

@@ -1399,10 +1399,10 @@ static void resolve_stack_conflicts(struct player *pplayer,
bounce_unit(aunit, verbose);
}
} unit_list_iterate_safe_end;
- }
+ }
} unit_list_iterate_safe_end;
}
-
+
/**********************************************************************//**
When in civil war or an alliance breaks there will potentially be units
from both sides coexisting on the same squares. This routine resolves
--
2.40.1

0 comments on commit 49eed3f

Please sign in to comment.