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

This does not fix the underlying problem.  But clients should not crash with
bad server data.  Check this datum as it is passed in from the network.

Only xaw checked its data for A_UNSET!  This updates that check, and fixes
gtk2 (and hopefully sdl and win32, although they remain untested).

Also, updated TRANS comments for various "(Unknown)", "(unknown)", and
"(none)" -- attempting some usage consistency.

Committed S2_1 revision 14257.
Committed S2_2 revision 14258 (patch attached for posterity).
Committed trunk revision 14259.




Index: server/stdinhand.c
===================================================================
--- server/stdinhand.c  (revision 14257)
+++ server/stdinhand.c  (working copy)
@@ -361,10 +361,15 @@
                           enum rfc_status rfc_status, const char *prefix,
                           const char *line)
 {
-  const char *cmdname = cmd < CMD_NUM ? commands[cmd].name :
-                  cmd == CMD_AMBIGUOUS ? _("(ambiguous)") :
-                  cmd == CMD_UNRECOGNIZED ? _("(unknown)") :
-                       "(?!?)";  /* this case is a bug! */
+  const char *cmdname = cmd < CMD_NUM
+                        ? commands[cmd].name
+                        : cmd == CMD_AMBIGUOUS
+                          /* TRANS: ambiguous command */
+                          ? _("(ambiguous)")
+                          : cmd == CMD_UNRECOGNIZED
+                            /* TRANS: unrecognized command */
+                            ? _("(unknown)")
+                            : "(?!?)";  /* this case is a bug! */
 
   if (caller) {
     notify_conn(caller->self, NULL, E_SETTING,
Index: common/tech.c
===================================================================
--- common/tech.c       (revision 14257)
+++ common/tech.c       (working copy)
@@ -895,7 +895,7 @@
   advances[A_FUTURE].name.translated = NULL;
 
   /* Initialize dummy tech A_UNKNOWN */
-  /* TRANS: "Unknown" tech */
+  /* TRANS: "Unknown" advance/technology */
   sz_strlcpy(advances[A_UNKNOWN].name.vernacular, N_("(Unknown)"));
   advances[A_UNKNOWN].name.translated = NULL;
 }
Index: common/team.c
===================================================================
--- common/team.c       (revision 14257)
+++ common/team.c       (working copy)
@@ -171,6 +171,7 @@
 const char *team_rule_name(const struct team *pteam)
 {
   if (!pteam) {
+    /* TRANS: missing value */
     return N_("(none)");
   }
   return game.info.team_names_orig[team_index(pteam)];
Index: common/requirements.c
===================================================================
--- common/requirements.c       (revision 14257)
+++ common/requirements.c       (working copy)
@@ -1158,6 +1158,7 @@
 {
   switch (psource->kind) {
   case VUT_NONE:
+    /* TRANS: missing value */
     return N_("(none)");
   case VUT_ADVANCE:
     return advance_rule_name(psource->value.advance);
@@ -1208,6 +1209,7 @@
   buf[0] = '\0'; /* to be safe. */
   switch (psource->kind) {
   case VUT_NONE:
+    /* TRANS: missing value */
     mystrlcat(buf, _("(none)"), bufsz);
     break;
   case VUT_ADVANCE:
Index: client/citydlg_common.c
===================================================================
--- client/citydlg_common.c     (revision 14257)
+++ client/citydlg_common.c     (working copy)
@@ -416,6 +416,7 @@
         * trade_value[] array and simply don't give the name of the
         * city. */
        struct city *trade_city = game_find_city_by_number(pcity->trade[i]);
+       /* TRANS: "unknown" location */
        const char *name = trade_city ? city_name(trade_city) : _("(unknown)");
 
        cat_snprintf(buf, bufsz, _("%+4d : Trade route with %s\n"),
Index: client/gui-gtk-2.0/inteldlg.c
===================================================================
--- client/gui-gtk-2.0/inteldlg.c       (revision 14257)
+++ client/gui-gtk-2.0/inteldlg.c       (working copy)
@@ -364,7 +364,8 @@
            break;
          case LABEL_CAPITAL:
            pcity = find_palace(p);
-           sz_strlcpy(buf, (!pcity) ? _("(Unknown)") : city_name(pcity));
+           /* TRANS: "unknown" location */
+           sz_strlcpy(buf, (!pcity) ? _("(unknown)") : city_name(pcity));
            break;
          case LABEL_GOLD:
            my_snprintf(buf, sizeof(buf), "%d", p->economic.gold);
@@ -380,13 +381,21 @@
            break;
          case LABEL_RESEARCHING: {
            struct player_research* research = get_player_research(p);
-           if (research->researching != A_UNKNOWN) {
+           switch (research->researching) {
+           case A_UNKNOWN:
+             /* TRANS: "Unknown" advance/technology */
+             my_snprintf(buf, sizeof(buf), _("(Unknown)"));
+             break;
+           case A_UNSET:
+             /* TRANS: missing value */
+             my_snprintf(buf, sizeof(buf), _("(none)"));
+             break;
+           default:
              my_snprintf(buf, sizeof(buf), "%s(%d/%d)",
                  advance_name_researching(p),
                  research->bulbs_researched, total_bulbs_required(p));
-           } else {
-             my_snprintf(buf, sizeof(buf), _("(Unknown)"));
-           }
+             break;
+           };
            break;
          }
          default:
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
--- client/gui-gtk-2.0/helpdlg.c        (revision 14257)
+++ client/gui-gtk-2.0/helpdlg.c        (working copy)
@@ -1056,7 +1056,7 @@
       }
       buf[strlen (buf) - 1] = '.';
     } else {
-      /* TRANS: (none) as in "Resources: (none)". */
+      /* TRANS: "Resources: (none)" */
       sprintf (buf + strlen (buf), _("(none)"));
     }
     gtk_label_set_text(GTK_LABEL(help_tlabel[1][1]), buf);
Index: client/gui-xaw/inteldlg.c
===================================================================
--- client/gui-xaw/inteldlg.c   (revision 14257)
+++ client/gui-xaw/inteldlg.c   (working copy)
@@ -237,16 +237,21 @@
                          XtNlabel, buf,
                          NULL);
 
-  if (get_player_research(pdialog->pplayer)->researching == A_UNSET
-      || get_player_research(pdialog->pplayer)->researching == A_UNKNOWN) {
+  switch (get_player_research(pdialog->pplayer)->researching) {
+  case A_UNKNOWN:
+    my_snprintf(buf, sizeof(buf), _("Researching: (Unknown)"));
+    break;
+  case A_UNSET:
     my_snprintf(buf, sizeof(buf), _("Researching: Unknown(%d/-)"),
                get_player_research(pdialog->pplayer)->bulbs_researched);
-  } else {
+    break;
+  default:
     my_snprintf(buf, sizeof(buf), _("Researching: %s(%d/%d)"),
                advance_name_researching(pdialog->pplayer),
                get_player_research(pdialog->pplayer)->bulbs_researched,
                total_bulbs_required(pdialog->pplayer));
-  }
+    break;
+  };
 
   XtVaCreateManagedWidget("intelreslabel",
                          labelWidgetClass,
@@ -256,7 +261,8 @@
 
   pcity = find_palace(pdialog->pplayer);
   my_snprintf(buf, sizeof(buf), _("Capital: %s"),
-             (!pcity) ? _("(Unknown)") : city_name(pcity));
+             /* TRANS: "unknown" location */
+             (!pcity) ? _("(unknown)") : city_name(pcity));
   XtVaCreateManagedWidget("intelcapitallabel",
                          labelWidgetClass,
                          pdialog->intel_form,
Index: client/gui-xaw/helpdlg.c
===================================================================
--- client/gui-xaw/helpdlg.c    (revision 14257)
+++ client/gui-xaw/helpdlg.c    (working copy)
@@ -993,7 +993,7 @@
       }
       buf[strlen (buf) - 1] = '.';
     } else {
-      /* TRANS: (none) as in "Resources: (none)". */
+      /* TRANS: "Resources: (none)". */
       sprintf (buf + strlen (buf), _("(none)"));
     }
     xaw_set_label(help_terrain_resources, buf);
Index: client/gui-win32/inteldlg.c
===================================================================
--- client/gui-win32/inteldlg.c (revision 14257)
+++ client/gui-win32/inteldlg.c (working copy)
@@ -124,19 +124,27 @@
   
   hbox=fcwin_hbox_new(intel_dialog,FALSE);
    
-  if (get_player_research(p)->researching != A_UNKNOWN) {
+  switch (get_player_research(p)->researching) {
+  case A_UNKNOWN:
+    my_snprintf(buf, sizeof(buf), _("Researching: (Unknown)"));
+    break;
+  case A_UNSET:
+    my_snprintf(buf, sizeof(buf), _("Researching: Unknown(%d/-)"),
+               get_player_research(p)->bulbs_researched);
+    break;
+  default:
     my_snprintf(buf, sizeof(buf), _("Researching: %s(%d/%d)"),
                advance_name_researching(p),
                get_player_research(p)->bulbs_researched,
                total_bulbs_required(p));
-  } else {
-    my_snprintf(buf, sizeof(buf), _("Researching: (Unknown)"));
-  }
+    break;
+  };
   fcwin_box_add_static(hbox,buf,0,SS_CENTER,TRUE,TRUE,10);
   
   pcity = find_palace(p);
   my_snprintf(buf, sizeof(buf), _("Capital: %s"),
-              (!pcity) ? _("(Unknown)") : city_name(pcity));
+              /* TRANS: "unknown" location */
+              (!pcity) ? _("(unknown)") : city_name(pcity));
   fcwin_box_add_static(hbox,buf,0,SS_CENTER,TRUE,TRUE,10);
   
   fcwin_box_add_box(vbox,hbox,FALSE,FALSE,5);
Index: client/gui-win32/helpdlg.c
===================================================================
--- client/gui-win32/helpdlg.c  (revision 14257)
+++ client/gui-win32/helpdlg.c  (working copy)
@@ -583,7 +583,7 @@
       }
       buf[strlen (buf) - 1] = '.';
     } else {
-      /* TRANS: (none) as in "Resources: (none)". */
+      /* TRANS: "Resources: (none)" */
       sprintf (buf + strlen (buf), _("(none)"));
     }
     SetWindowText(help_tlabel[1][1], buf);
Index: client/packhand.c
===================================================================
--- client/packhand.c   (revision 14257)
+++ client/packhand.c   (working copy)
@@ -1647,7 +1647,16 @@
   pplayer->bulbs_last_turn = pinfo->bulbs_last_turn;
   research->bulbs_researched = pinfo->bulbs_researched;
   research->techs_researched = pinfo->techs_researched;
-  research->researching=pinfo->researching;
+
+  /* check for bad values, complicated by discontinuous range */
+  if (NULL == advance_by_number(pinfo->researching)
+   && A_UNKNOWN != pinfo->researching
+   && A_FUTURE != pinfo->researching
+   && A_UNSET != pinfo->researching) {
+    research->researching = A_NONE; /* should never happen */
+  } else {
+    research->researching = pinfo->researching;
+  }
   research->future_tech = pinfo->future_tech;
   research->tech_goal=pinfo->tech_goal;
   
Index: client/gui-sdl/inteldlg.c
===================================================================
--- client/gui-sdl/inteldlg.c   (revision 14257)
+++ client/gui-sdl/inteldlg.c   (working copy)
@@ -280,27 +280,37 @@
     research = get_player_research(p);
     change_ptsize16(pStr, adj_font(10));
     pStr->style &= ~TTF_STYLE_BOLD;
-    if (research->researching != A_UNKNOWN) {
+
+    /* FIXME: these should use common gui code, and avoid duplication! */
+    switch (research->researching) {
+    case A_UNKNOWN:
+    case A_UNSET:
       my_snprintf(cBuf, sizeof(cBuf),
         _("Ruler: %s %s  Government: %s\nCapital: %s  Gold: %d\nTax: %d%%"
-          " Science: %d%% Luxury: %d%%\nResearching: %s(%d/%d)"),
+          " Science: %d%% Luxury: %d%%\nResearching: unknown"),
         ruler_title_translation(p),
         player_name(p),
         government_name_for_player(p),
-        (!pCapital) ? _("(Unknown)") : city_name(pCapital), p->economic.gold,
-        p->economic.tax, p->economic.science, p->economic.luxury,
-        advance_name_researching(p),
-        research->bulbs_researched, total_bulbs_required(p));
-    } else {
+        /* TRANS: "unknown" location */
+        (!pCapital) ? _("(unknown)") : city_name(pCapital),
+        p->economic.gold,
+        p->economic.tax, p->economic.science, p->economic.luxury);
+      break;
+    default:
       my_snprintf(cBuf, sizeof(cBuf),
         _("Ruler: %s %s  Government: %s\nCapital: %s  Gold: %d\nTax: %d%%"
-          " Science: %d%% Luxury: %d%%\nResearching: Unknown"),
+          " Science: %d%% Luxury: %d%%\nResearching: %s(%d/%d)"),
         ruler_title_translation(p),
         player_name(p),
         government_name_for_player(p),
-        (!pCapital) ? _("(Unknown)") : city_name(pCapital), p->economic.gold,
-        p->economic.tax, p->economic.science, p->economic.luxury);
-    }
+        /* TRANS: "unknown" location */
+        (!pCapital) ? _("(unknown)") : city_name(pCapital),
+        p->economic.gold,
+        p->economic.tax, p->economic.science, p->economic.luxury,
+        advance_name_researching(p),
+        research->bulbs_researched, total_bulbs_required(p));
+      break;
+    };
     
     copy_chars_to_string16(pStr, cBuf);
     pInfo = create_text_surf_from_str16(pStr);
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to