[libgweather/wip/hadess/serialisation-fix-stable] GWeatherLocation: Fix crash when serialising detached cities



commit 50ac319c269eca2a2e27eb7ecb475e214651a83c
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Oct 9 20:10:59 2018 +0200

    GWeatherLocation: Fix crash when serialising detached cities
    
    Such as the ones without children, or without a weather station code

 libgweather/gweather-location.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
---
diff --git a/libgweather/gweather-location.c b/libgweather/gweather-location.c
index 6ddb1c0..ce55a68 100644
--- a/libgweather/gweather-location.c
+++ b/libgweather/gweather-location.c
@@ -1387,8 +1387,9 @@ gweather_location_format_two_serialize (GWeatherLocation *location)
 
     /* Normalize location to be a weather station or detached */
     if (location->level == GWEATHER_LOCATION_CITY) {
-       location = location->children[0];
-       is_city = TRUE;
+        if (location->children != NULL)
+            location = location->children[0];
+        is_city = TRUE;
     } else {
        is_city = FALSE;
     }
@@ -1402,7 +1403,7 @@ gweather_location_format_two_serialize (GWeatherLocation *location)
        g_variant_builder_add (&parent_latlon_builder, "(dd)", location->parent->latitude, 
location->parent->longitude);
 
     return g_variant_new ("(ssba(dd)a(dd))",
-                         name, location->station_code, is_city,
+                         name, location->station_code ? location->station_code : "", is_city,
                          &latlon_builder, &parent_latlon_builder);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]