From 6589601e56508a00b879e9c7fae970e8ff88cd30 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 16 Sep 2008 21:47:55 -0400 Subject: [PATCH] Make unit_give_away() immune to infinite recursion Put the unit before recursing into its cargo. This breaks cycles in the "is loaded on" relations. Such cycles exist only in a corrupt game state. Mildly inefficient, because callers typically put the unit again. --- src/lib/subs/unitsub.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/subs/unitsub.c b/src/lib/subs/unitsub.c index dff5ecbb..a5a3655d 100644 --- a/src/lib/subs/unitsub.c +++ b/src/lib/subs/unitsub.c @@ -301,13 +301,12 @@ unit_give_away(struct empobj *unit, natid recipient, natid giver) unit->own = recipient; unit_wipe_orders(unit); + put_empobj(unit->ef_type, unit->uid, unit); for (type = EF_PLANE; type <= EF_NUKE; type++) { snxtitem_cargo(&ni, type, unit->ef_type, unit->uid); - while (nxtitem(&ni, &cargo)) { + while (nxtitem(&ni, &cargo)) unit_give_away(&cargo.gen, recipient, giver); - put_empobj(type, cargo.gen.uid, &cargo.gen); - } } }