]> git.pond.sub.org Git - empserver/commitdiff
Make unit_give_away() immune to infinite recursion
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 17 Sep 2008 01:47:55 +0000 (21:47 -0400)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 17 Sep 2008 01:47:55 +0000 (21:47 -0400)
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

index dff5ecbb971773d2417c4e9ca4f3790749a3c57c..a5a3655d612d3435f439d97806d39b0e95fd4ab2 100644 (file)
@@ -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);
-       }
     }
 }