[Freeciv-Dev] (PR#10967) helpdlg crash with too-long translated names
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10967 >
> [jdorje - Wed Nov 10 17:52:46 2004]:
> 7. helptext_building crashes on B_LAST.
Here's a patch. Instead the functions will print an error message and
return. (We could use an assert here, that would be okay too.)
jason
Index: client/helpdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/helpdata.c,v
retrieving revision 1.83
diff -u -r1.83 helpdata.c
--- client/helpdata.c 11 Nov 2004 14:44:20 -0000 1.83
+++ client/helpdata.c 13 Nov 2004 09:02:56 -0000
@@ -504,11 +504,18 @@
char *helptext_building(char *buf, size_t bufsz, Impr_Type_id which,
const char *user_text)
{
- struct impr_type *imp = &improvement_types[which];
-
+ struct impr_type *imp;
+
assert(buf);
buf[0] = '\0';
+ if (improvement_exists(which)) {
+ freelog(LOG_ERROR, "Unknown building %d.", which);
+ return buf;
+ }
+
+ imp = &improvement_types[which];
+
if (imp->helptext && imp->helptext[0] != '\0') {
my_snprintf(buf + strlen(buf), bufsz - strlen(buf),
"%s\n\n", _(imp->helptext));
@@ -643,6 +650,7 @@
assert(buf&&user_text);
if (!unit_type_exists(i)) {
+ freelog(LOG_ERROR, "Unknown unit %d.", i);
strcpy(buf, user_text);
return;
}
@@ -969,6 +977,12 @@
assert(buf&&user_text);
strcpy(buf, user_text);
+ if (!tech_exists(i)) {
+ freelog(LOG_ERROR, "Unknown tech %d.", i);
+ strcpy(buf, user_text);
+ return;
+ }
+
if (get_invention(game.player_ptr, i) != TECH_KNOWN) {
if (get_invention(game.player_ptr, i) == TECH_REACHABLE) {
sprintf(buf + strlen(buf),
@@ -1081,8 +1095,10 @@
buf[0] = '\0';
- if (i<0 || i>=T_COUNT)
+ if (i < 0 || i >= T_COUNT) {
+ freelog(LOG_ERROR, "Unknown terrain %d.", i);
return;
+ }
pt = &tile_types[i];
if (pt->helptext[0] != '\0') {
@@ -1097,10 +1113,16 @@
*****************************************************************/
void helptext_government(char *buf, int i, const char *user_text)
{
- struct government *gov = get_government(i);
+ struct government *gov;
buf[0] = '\0';
-
+
+ if (i < 0 || i >= game.government_count) {
+ freelog(LOG_ERROR, "Unknown government %d.", i);
+ return;
+ }
+
+ gov = get_government(i);
if (gov->helptext[0] != '\0') {
sprintf(buf, "%s\n\n", _(gov->helptext));
}
@@ -1114,7 +1136,14 @@
char *helptext_unit_upkeep_str(int i)
{
static char buf[128];
- struct unit_type *utype = get_unit_type(i);
+ struct unit_type *utype;
+
+ if (!unit_type_exists(i)) {
+ freelog(LOG_ERROR, "Unknown unit %d.", i);
+ return "";
+ }
+
+ utype = get_unit_type(i);
if (utype->shield_cost > 0 || utype->food_cost > 0
|| utype->gold_cost > 0 || utype->happy_cost > 0) {
|
|