From 2629c993cf1ef104cd343395aa45524836446577 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 19 Oct 2021 14:57:47 -0400 Subject: 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. --- json-glib/json-parser.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'json-glib/json-parser.c') 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); } -- cgit v1.2.1