<URL: http://bugs.freeciv.org/Ticket/Display.html?id=17982 >

On 23/06/2006, Billy Naylor <[EMAIL PROTECTED]> wrote:
>
> using revision 12030 of freeciv 2.1.0
>
> a broken rndCIv ruleset had Ballista & Catapult obsolete each other,
> which meant the client froze when the first city was created.
>
> this should have been caught by the server when it parsed rulesets.

 Attached patch catches upgrade loops when parsing rulesets.


 - ML

diff -Nurd -X.diff_ignore freeciv/server/ruleset.c freeciv/server/ruleset.c
--- freeciv/server/ruleset.c	2007-08-11 21:57:28.000000000 +0300
+++ freeciv/server/ruleset.c	2007-08-31 03:10:53.000000000 +0300
@@ -3273,6 +3273,8 @@
 **************************************************************************/
 static bool sanity_check_ruleset_data(void)
 {
+  int num_utypes;
+
   /* Check that all players can have their initial techs */
   nations_iterate(pnation) {
     int i;
@@ -3321,5 +3323,22 @@
     }
   } players_iterate_end;
 
+  /* Check against unit upgrade loops */
+  num_utypes = game.control.num_unit_types;
+  unit_type_iterate(putype) {
+    int chain_length = 0;
+    struct unit_type *upgraded = putype;
+
+    while(upgraded != NULL) {
+      upgraded = upgraded->obsoleted_by;
+      chain_length++;
+      if (chain_length > num_utypes) {
+        freelog(LOG_FATAL, "There seems to be obsoleted_by loop in update "
+                "chain that starts from %s", utype_rule_name(putype));
+        exit(EXIT_FAILURE);
+      }
+    }
+  } unit_type_iterate_end;
+
   return TRUE;
 }
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to