Author: cazfi
Date: Wed Aug 26 19:56:52 2015
New Revision: 29686

URL: http://svn.gna.org/viewcvs/freeciv?rev=29686&view=rev
Log:
Avoid sdl/2-client crash if update_unit_info_label() is called with NULL 
unitlist.

See bug #23809

Modified:
    trunk/client/gui-sdl/mapview.c
    trunk/client/gui-sdl2/mapview.c

Modified: trunk/client/gui-sdl/mapview.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl/mapview.c?rev=29686&r1=29685&r2=29686&view=diff
==============================================================================
--- trunk/client/gui-sdl/mapview.c      (original)
+++ trunk/client/gui-sdl/mapview.c      Wed Aug 26 19:56:52 2015
@@ -506,10 +506,15 @@
   SDL_Surface *pBuf_Surf, *pTmpSurf;
   SDL_String16 *pStr;
   struct canvas *destcanvas;
-  struct unit *pUnit = unit_list_get(punitlist, 0);
+  struct unit *pUnit;
+
+  if (punitlist != NULL && unit_list_size(punitlist) > 0) {
+    pUnit = unit_list_get(punitlist, 0);
+  } else {
+    pUnit = NULL;
+  }
 
   if (SDL_Client_Flags & CF_UNITINFO_SHOWN) {
-    
     pInfo_Window = get_unit_info_window_widget();
 
     /* blit theme surface */
@@ -975,7 +980,7 @@
   the square under the current unit, for specified unit.  Note that in
   practice punit is always the focus unit.
 
-  Clears label if punit is NULL.
+  Clears label if punitlist is NULL or empty.
 
   Typically also updates the cursor for the map_canvas (this is related
   because the info label may includes  "select destination" prompt etc).

Modified: trunk/client/gui-sdl2/mapview.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/client/gui-sdl2/mapview.c?rev=29686&r1=29685&r2=29686&view=diff
==============================================================================
--- trunk/client/gui-sdl2/mapview.c     (original)
+++ trunk/client/gui-sdl2/mapview.c     Wed Aug 26 19:56:52 2015
@@ -522,7 +522,13 @@
   SDL_Surface *buf_surf;
   utf8_str *pstr;
   struct canvas *destcanvas;
-  struct unit *pUnit = unit_list_get(punitlist, 0);
+  struct unit *pUnit;
+
+  if (punitlist != NULL && unit_list_size(punitlist) > 0) {
+    pUnit = unit_list_get(punitlist, 0);
+  } else {
+    pUnit = NULL;
+  }
 
   if (SDL_Client_Flags & CF_UNITINFO_SHOWN) {
     pInfo_Window = get_unit_info_window_widget();
@@ -993,7 +999,7 @@
   the square under the current unit, for specified unit.  Note that in
   practice punit is always the focus unit.
 
-  Clears label if punit is NULL.
+  Clears label if punitlist is NULL or empty.
 
   Typically also updates the cursor for the map_canvas (this is related
   because the info label may includes  "select destination" prompt etc).


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to