Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2005:
[Freeciv-Dev] Re: (PR#14984) GTK2 client segfaults at end of game
Home

[Freeciv-Dev] Re: (PR#14984) GTK2 client segfaults at end of game

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: guillaume.melquiond@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#14984) GTK2 client segfaults at end of game
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 25 Dec 2005 18:15:02 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Guillaume Melquiond wrote:
> <URL: http://bugs.freeciv.org/Ticket/Display.html?id=14984 >
> 
> Backtrace:
> 
> #0  0x0807ba8b in get_unit_info_label_text1 (punits=0x0) at speclist.h:110
>         str = {str = 0x91eff30 "0 units", n = 8, n_alloc = 37}
>         count = <value optimized out>
> #1  0x08107378 in update_unit_info_label (punits=0x0) at mapview.c:212
>         label = (GtkWidget *) 0x8c1c2a0
> #2  0x0806f899 in handle_game_state (value=4) at packhand.c:376
> 
> According to its comment, update_unit_info_label is supposed to clear
> labels when its argument is NULL. Yet it does not test for it, and
> get_unit_info_label_text1 later segfaults when it tries to get the
> size of punits.

An obnoxious problem, but this should fix it.

-jason

Index: client/control.c
===================================================================
--- client/control.c    (revision 11386)
+++ client/control.c    (working copy)
@@ -666,7 +666,7 @@
 
   /* Check for any change in the unit's state.  This assumes that a unit's
    * orders cannot be changed directly but must be removed and then reset. */
-  if (unit_list_size(punitlist) > 0
+  if (punitlist && unit_list_size(punitlist) > 0
       && get_client_state() != CLIENT_GAME_OVER_STATE) {
     /* There used to be a complicated and bug-prone check here to see if
      * the unit had actually changed.  This was misguided since the stacked
Index: client/text.c
===================================================================
--- client/text.c       (revision 11386)
+++ client/text.c       (working copy)
@@ -639,14 +639,17 @@
 const char *get_unit_info_label_text1(struct unit_list *punits)
 {
   static struct astring str = ASTRING_INIT;
-  int count = unit_list_size(punits);
 
   astr_clear(&str);
 
-  if (count == 1) {
-    astr_add(&str, "%s", unit_list_get(punits, 0)->type->name);
-  } else {
-    astr_add(&str, PL_("%d unit", "%d units", count), count);
+  if (punits) {
+    int count = unit_list_size(punits);
+
+    if (count == 1) {
+      astr_add(&str, "%s", unit_list_get(punits, 0)->type->name);
+    } else {
+      astr_add(&str, PL_("%d unit", "%d units", count), count);
+    }
   }
   return str.str;
 }
@@ -659,10 +662,16 @@
 const char *get_unit_info_label_text2(struct unit_list *punits)
 {
   static struct astring str = ASTRING_INIT;
-  int count = unit_list_size(punits);
+  int count;
 
   astr_clear(&str);
 
+  if (!punits) {
+    return "";
+  }
+
+  count = unit_list_size(punits);
+
   /* This text should always have the same number of lines.  Otherwise the
    * GUI widgets may be confused and try to resize themselves. */
 

[Prev in Thread] Current Thread [Next in Thread]