From e83fe9a5d7d2d000f34d7ac01d3266c23f830611 Mon Sep 17 00:00:00 2001 From: Jakob Olsson <Jakob Olsson> Date: Wed, 11 Dec 2019 12:16:38 +0100 Subject: [PATCH] minor fixes for definition handling --- src/json-validator.cpp | 6 ++++-- src/schema.cpp | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 88278a0..a0a81d9 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -36,14 +36,16 @@ static void loader(const json_uri &uri, json &schema) s_def = schema_get_definitions_schema(uri.url().c_str()); if (!s_def) - return; + throw std::invalid_argument("could not find " + uri.url()); + str = blobmsg_format_json(s_def->definitions, true); if (!str) - return; + throw std::invalid_argument("could not allocate memory for definition"); schema = json::parse(str); + free(str); } diff --git a/src/schema.cpp b/src/schema.cpp index f7846e1..5866d0d 100644 --- a/src/schema.cpp +++ b/src/schema.cpp @@ -96,7 +96,7 @@ static void schema_flush_definitions(void) { struct schema_definition *s_def, *tmp; - dbg("cleaning all schema objects\n"); + dbg("cleaning all schema definitions\n"); avl_for_each_element_safe(&s_ctx.schema_definitions, s_def, avl, tmp) { avl_delete(&s_ctx.schema_objects, &s_def->avl); @@ -331,12 +331,13 @@ schema_setup(void) unsigned int i; glob_t gl; + avl_init(&s_ctx.schema_objects, avl_strcmp, false, NULL); + avl_init(&s_ctx.schema_definitions, avl_strcmp, false, NULL); + /* setup docs */ if (glob(JSON_SCHEMA_DIR "/*.json", 0, NULL, &gl)) return; - avl_init(&s_ctx.schema_objects, avl_strcmp, false, NULL); - for (i = 0; i < gl.gl_pathc; i++) { dbg("doc path = %s\n", gl.gl_pathv[i]); schema_setup_documents(gl.gl_pathv[i]); -- GitLab