[Freeciv-Dev] Re: (PR#4798) Server crash at turn done
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Sat, 9 Aug 2003, Christian Knoke wrote:
> (gdb) bt
> #00x080b828c in unit_type (punit=0x10) at unittype.c:96
> #10x0806872f in city_distribute_surplus_shields (pplayer=0x816e2ec,
> pcity=0x86ed4b0)
> at cityturn.c:906
Ah, yes. Another case of disbanding a ferry in the middle of a
unit_list_iterate(). We should of course be using the safe list iterator
here. Patch attached. Will commit immediately.
The drawback is of course that the safe iterator is slower to start since
it does a malloc.
- Per
"This is the future for the world we're in at the moment,"
promised Lawrence Di Rita, special assistant to Rumsfeld.
"We'll get better as we do it more often."
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.220
diff -u -r1.220 cityturn.c
--- server/cityturn.c 8 Aug 2003 21:31:36 -0000 1.220
+++ server/cityturn.c 9 Aug 2003 19:16:14 -0000
@@ -27,6 +27,7 @@
#include "government.h"
#include "log.h"
#include "map.h"
+#include "mem.h"
#include "player.h"
#include "rand.h"
#include "shared.h"
@@ -902,7 +903,7 @@
struct government *g = get_gov_pplayer(pplayer);
if (pcity->shield_surplus < 0) {
- unit_list_iterate(pcity->units_supported, punit) {
+ unit_list_iterate_safe(pcity->units_supported, punit) {
if (utype_shield_cost(unit_type(punit), g) > 0
&& pcity->shield_surplus < 0
&& !unit_flag(punit, F_UNDISBANDABLE)) {
@@ -915,7 +916,7 @@
handle_unit_disband(pplayer, &packet);
/* pcity->shield_surplus is automatically updated. */
}
- } unit_list_iterate_end;
+ } unit_list_iterate_safe_end;
}
if (pcity->shield_surplus < 0) {
@@ -923,7 +924,7 @@
* It'd rather make the citizens pay in blood for their failure to upkeep
* it! If we make it here all normal units are already disbanded, so only
* undisbandable ones remain. */
- unit_list_iterate(pcity->units_supported, punit) {
+ unit_list_iterate_safe(pcity->units_supported, punit) {
int upkeep = utype_shield_cost(unit_type(punit), g);
if (upkeep > 0 && pcity->shield_surplus < 0) {
@@ -938,7 +939,7 @@
/* No upkeep for the unit this turn. */
pcity->shield_surplus += upkeep;
}
- } unit_list_iterate_end;
+ } unit_list_iterate_safe_end;
}
/* Now we confirm changes made last turn. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: (PR#4798) Server crash at turn done,
Per I. Mathisen <=
|
|