JSON parser REFACTOR redesign labels to avoid forward and backwards gotos
Reported by LGTM.
diff --git a/src/parser_json.c b/src/parser_json.c
index 6348459..d17adc4 100644
--- a/src/parser_json.c
+++ b/src/parser_json.c
@@ -803,9 +803,8 @@
ret = lyjson_ctx_next(lydctx->jsonctx, NULL);
LY_CHECK_GOTO(ret, cleanup);
-cleanup:
- LOG_LOCBACK(ctx, 1, 0, 0, 0);
- return ret;
+ /* success */
+ goto cleanup;
representation_error:
LOGVAL(ctx, LYVE_SYNTAX_JSON,
@@ -814,7 +813,10 @@
expected, lyjson_token2str(status), in_parent ? "" : "name");
ret = LY_EVALID;
- goto cleanup;
+
+cleanup:
+ LOG_LOCBACK(ctx, 1, 0, 0, 0);
+ return ret;
}
/**
@@ -1290,9 +1292,8 @@
/* finally connect the parsed node */
lydjson_maintain_children(parent, first_p, &node);
-cleanup:
- lyd_free_tree(node);
- return ret;
+ /* success */
+ goto cleanup;
representation_error:
LOG_LOCSET(ctx, NULL, (const struct lyd_node *)parent, NULL, NULL);
@@ -1300,7 +1301,10 @@
lys_nodetype2str(snode->nodetype), snode->name, expected, lyjson_token2str(status));
LOG_LOCBACK(ctx, 0, parent ? 1 : 0, 0, 0);
ret = LY_EVALID;
- goto cleanup;
+
+cleanup:
+ lyd_free_tree(node);
+ return ret;
}
/**