Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8755) minor nation cleanup
Home

[Freeciv-Dev] (PR#8755) minor nation cleanup

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8755) minor nation cleanup
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 16 May 2004 13:02:56 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8755 >

This patch makes some minor cleanups and fixes a buglet.

- Replace some -1 values with NO_NATION_SELECTED.

- If a nation can't be found at startup, give an error message and exit 
(rather than continuing and getting a cryptic crash later).

jason

? eff
Index: common/nation.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/nation.c,v
retrieving revision 1.37
diff -u -r1.37 nation.c
--- common/nation.c     15 Sep 2003 16:51:07 -0000      1.37
+++ common/nation.c     16 May 2004 20:01:41 -0000
@@ -68,7 +68,7 @@
      if(mystrcasecmp(name, get_nation_name (i)) == 0)
        return i;
 
-  return -1;
+  return NO_NATION_SELECTED;
 }
 
 /***************************************************************
@@ -82,7 +82,7 @@
      if(mystrcasecmp(name, get_nation_name_orig (i)) == 0)
        return i;
 
-  return -1;
+  return NO_NATION_SELECTED;
 }
 
 /***************************************************************
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.170
diff -u -r1.170 ruleset.c
--- server/ruleset.c    11 May 2004 17:18:20 -0000      1.170
+++ server/ruleset.c    16 May 2004 20:01:42 -0000
@@ -2324,7 +2324,7 @@
        * find_nation_by_name_orig. */
       pl->civilwar_nations[j] = find_nation_by_name(civilwar_nations[k]);
 
-      if (pl->civilwar_nations[j] == -1) {
+      if (pl->civilwar_nations[j] == NO_NATION_SELECTED) {
        j--;
        /* For nation authors this would probably be considered an error.
         * But it can happen normally.  The civ1 compatability ruleset only
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.150
diff -u -r1.150 savegame.c
--- server/savegame.c   15 May 2004 22:41:37 -0000      1.150
+++ server/savegame.c   16 May 2004 20:01:43 -0000
@@ -619,7 +619,7 @@
                        struct section_file *file)
 {
   int i, j, x, y, nunits, ncities, c_s;
-  char *p;
+  const char *p;
   char *savefile_options = secfile_lookup_str(file, "savefile.options");
   enum unit_activity activity;
   struct ai_data *ai;
@@ -658,9 +658,20 @@
       "filipino", "estonian", "latvian", "boer", "silesian", "singaporean",
       "chilean", "catalan", "croatian", "slovenian", "serbian", "barbarian",
     };
-    p = (char *)name_order[secfile_lookup_int(file, "player%d.race", plrno)];
+    int index = secfile_lookup_int(file, "player%d.race", plrno);
+
+    if (index >= 0 && index < ARRAY_SIZE(name_order)) {
+      p = name_order[index];
+    } else {
+      p = "";
+    }
   }
   plr->nation = find_nation_by_name_orig(p);
+  if (plr->nation == NO_NATION_SELECTED) {
+    freelog(LOG_FATAL, "Nation %s (used by %s) isn't available.",
+           p, plr->name);
+    exit(EXIT_FAILURE);
+  }
 
   /* Add techs from game and nation, but ignore game.tech. */
   init_tech(plr, 0);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8755) minor nation cleanup, Jason Short <=