From 501c9fb3805c9236fc008032295e0cdd87c4df47 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Sat, 1 Feb 2014 22:52:27 +0100 Subject: 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 --- json-glib/json-reader.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'json-glib') 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; -- cgit v1.2.1