From 443dc33370396a1ba474b74b519742a143058ad3 Mon Sep 17 00:00:00 2001 From: Sourav Moitra Date: Fri, 29 Nov 2024 15:37:22 +0530 Subject: [PATCH] Some improvements Signed-off-by: Sourav Moitra --- src/ocispec/json_common.c | 6 +++++- src/ocispec/sources.py | 8 +------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/ocispec/json_common.c b/src/ocispec/json_common.c index 9a30b0ce..477f435c 100644 --- a/src/ocispec/json_common.c +++ b/src/ocispec/json_common.c @@ -634,7 +634,7 @@ make_json_map_string_string (json_t *src, const struct parser_context *ctx, return NULL; } - ret->len = 0; + ret->len = len; ret->keys = calloc (len + 1, sizeof (char *)); if (ret->keys == NULL) @@ -685,6 +685,10 @@ make_json_map_string_string (json_t *src, const struct parser_context *ctx, i++; } + if (i == 0) { + return NULL; + } + return move_ptr (ret); } diff --git a/src/ocispec/sources.py b/src/ocispec/sources.py index 9ca56128..dd9f7364 100755 --- a/src/ocispec/sources.py +++ b/src/ocispec/sources.py @@ -366,18 +366,12 @@ def get_obj_arr_obj_array(obj, c_file, prefix): typename = obj.subtypname else: typename = helpers.get_name_substr(obj.name, prefix) - - if obj.doublearray: - root_type = "array" - else: - root_type = "object" - c_file.append(f' if (ptr != NULL && ptr->{obj.fixname} != NULL)\n') c_file.append(' {\n') c_file.append(' size_t len = 0, i;\n') c_file.append(f" if (ptr != NULL && ptr->{obj.fixname} != NULL)\n") c_file.append(f" len = ptr->{obj.fixname}_len;//{obj.subtypobj}\n") - c_file.append(f' json_t *subroot = json_{root_type}();//lalala\n') + c_file.append(f' json_t *subroot = json_array();//lalala\n') c_file.append(' for (i = 0; i < len; i++)\n') c_file.append(' {\n') if obj.doublearray: