[json-glib] reader: When a read() fails, don't track back on end()
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] reader: When a read() fails, don't track back on end()
- Date: Mon, 3 Feb 2014 14:11:55 +0000 (UTC)
commit 501c9fb3805c9236fc008032295e0cdd87c4df47
Author: Bastien Nocera <hadess hadess net>
Date: Sat Feb 1 22:52:27 2014 +0100
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 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]