summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2021-10-19 14:57:47 -0400
committerRay Strode <rstrode@redhat.com>2021-10-19 15:42:20 -0400
commit2629c993cf1ef104cd343395aa45524836446577 (patch)
treeeb156e87ef82604a8c36752c826a1854798311b8
parenta64aff2b4ae07e86f4f0fa3f3e9c17d4214f5e92 (diff)
downloadjson-glib-2629c993cf1ef104cd343395aa45524836446577.tar.gz
builder,parser: Use g_assert for sanity checks
Coverity noticed a leak in json_builder_get_root that can't happen in practice. Namely, if internal state gets screwed up and runtime checks are enabled, json_builder_get_root may return NULL without freeing a copy of the builder root it just made. This is because of a g_return_val_if_fail call to bail early if an internal consistency sanity check fails. This commit addresses the coverity complaint by using g_assert instead of g_return_val_if_fail for this sanity check, and other similar sanity checks, in the code.
-rw-r--r--json-glib/json-builder.c6
-rw-r--r--json-glib/json-parser.c12
2 files changed, 9 insertions, 9 deletions
diff --git a/json-glib/json-builder.c b/json-glib/json-builder.c
index 45f6cbe..1106ae5 100644
--- a/json-glib/json-builder.c
+++ b/json-glib/json-builder.c
@@ -315,9 +315,9 @@ json_builder_get_root (JsonBuilder *builder)
root = json_node_copy (builder->priv->root);
/* Sanity check. */
- g_return_val_if_fail (!builder->priv->immutable ||
- root == NULL ||
- json_node_is_immutable (root), NULL);
+ g_assert (!builder->priv->immutable ||
+ root == NULL ||
+ json_node_is_immutable (root));
return root;
}
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index c5e58f4..27cd07a 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -1299,9 +1299,9 @@ json_parser_get_root (JsonParser *parser)
g_return_val_if_fail (JSON_IS_PARSER (parser), NULL);
/* Sanity check. */
- g_return_val_if_fail (parser->priv->root == NULL ||
- !parser->priv->is_immutable ||
- json_node_is_immutable (parser->priv->root), NULL);
+ g_assert (parser->priv->root == NULL ||
+ !parser->priv->is_immutable ||
+ json_node_is_immutable (parser->priv->root));
return parser->priv->root;
}
@@ -1327,9 +1327,9 @@ json_parser_steal_root (JsonParser *parser)
g_return_val_if_fail (JSON_IS_PARSER (parser), NULL);
/* Sanity check. */
- g_return_val_if_fail (parser->priv->root == NULL ||
- !parser->priv->is_immutable ||
- json_node_is_immutable (parser->priv->root), NULL);
+ g_assert (parser->priv->root == NULL ||
+ !parser->priv->is_immutable ||
+ json_node_is_immutable (parser->priv->root));
return g_steal_pointer (&priv->root);
}