[geocode-glib] reader: fix json-glib usage



commit 67231f8eef71b1367f13f57e79c7e745c81d85f3
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Mon Feb 24 15:05:57 2014 +0100

    reader: fix json-glib usage
    
    This patch fixes two issues with our json-glib usage.
    
    * Do not atempt to read a string value when the node does not
      hold a string.
    
    * Make sure to call _end_member() when _read_member() fails.
    
    Without these fixes our code will result in segmentation fault.
    
    We were relying on the old buggy behaviour of json-glib that has been
    fixed up in:
    501c9fb reader: When a read() fails, don't track back on end()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=724927

 geocode-glib/geocode-reverse.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)
---
diff --git a/geocode-glib/geocode-reverse.c b/geocode-glib/geocode-reverse.c
index 23503d5..ea372bf 100644
--- a/geocode-glib/geocode-reverse.c
+++ b/geocode-glib/geocode-reverse.c
@@ -133,9 +133,12 @@ _geocode_read_nominatim_attributes (JsonReader *reader,
                 json_reader_read_member (reader, members[i]);
 
                 if (json_reader_is_value (reader)) {
-                        value = json_reader_get_string_value (reader);
-                        if (value && *value == '\0')
-                                value = NULL;
+                        JsonNode *node = json_reader_get_value (reader);
+                        if (json_node_get_value_type (node) == G_TYPE_STRING) {
+                                value = json_node_get_string (node);
+                                if (value && *value == '\0')
+                                        value = NULL;
+                        }
                 }
 
                 if (value != NULL) {
@@ -182,10 +185,9 @@ _geocode_read_nominatim_attributes (JsonReader *reader,
 
        g_strfreev (members);
 
-       if (json_reader_read_member (reader, "address")) {
+        if (json_reader_read_member (reader, "address"))
                 _geocode_read_nominatim_attributes (reader, ht);
-                json_reader_end_member (reader);
-        }
+        json_reader_end_member (reader);
 }
 
 static GHashTable *


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