summaryrefslogtreecommitdiff
path: root/json-glib
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2014-02-01 22:52:27 +0100
committerBastien Nocera <hadess@hadess.net>2014-02-03 15:11:15 +0100
commit501c9fb3805c9236fc008032295e0cdd87c4df47 (patch)
treee33907b95bc4b1cc4c408412bebc5ad8720d9d1b /json-glib
parent40abd7add9e3fa7288fdd144fd96da5270a86663 (diff)
downloadjson-glib-501c9fb3805c9236fc008032295e0cdd87c4df47.tar.gz
reader: When a read() fails, don't track back on end()
When a call to json_reader_read_element() fails if the element doesn't exist, we need to call json_reader_end_element() to clear out any errors. But the _end_element() call will backtrack to the parent node, when the _read_element() call did not set the child node. To fix this, leave early from _end_*() calls when an error has been set. https://bugzilla.gnome.org/show_bug.cgi?id=723428
Diffstat (limited to 'json-glib')
-rw-r--r--json-glib/json-reader.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/json-glib/json-reader.c b/json-glib/json-reader.c
index cb2ecd7..16a50e7 100644
--- a/json-glib/json-reader.c
+++ b/json-glib/json-reader.c
@@ -221,12 +221,18 @@ json_reader_new (JsonNode *node)
* @reader: a #JsonReader
*
* Unsets the error state of @reader, if set
+ *
+ * Return value: TRUE if an error was set.
*/
-static inline void
+static inline gboolean
json_reader_unset_error (JsonReader *reader)
{
if (reader->priv->error != NULL)
- g_clear_error (&(reader->priv->error));
+ {
+ g_clear_error (&(reader->priv->error));
+ return TRUE;
+ }
+ return FALSE;
}
/**
@@ -527,7 +533,8 @@ json_reader_end_element (JsonReader *reader)
g_return_if_fail (JSON_IS_READER (reader));
- json_reader_unset_error (reader);
+ if (json_reader_unset_error (reader))
+ return;
priv = reader->priv;
@@ -676,7 +683,8 @@ json_reader_end_member (JsonReader *reader)
g_return_if_fail (JSON_IS_READER (reader));
- json_reader_unset_error (reader);
+ if (json_reader_unset_error (reader))
+ return;
priv = reader->priv;