Skip to content

Commit

Permalink
Calculate of len on residual
Browse files Browse the repository at this point in the history
Signed-off-by: Sourav Moitra <[email protected]>
  • Loading branch information
xw19 committed Dec 19, 2024
1 parent 1a8e131 commit 544a0ed
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/ocispec/json_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,6 @@ make_json_map_string_string (json_t *src, const struct parser_context *ctx,

if (value != NULL)
{
char *str;
if (! json_is_string (value))
{
if (*err == NULL && asprintf (err, "Invalid value with type 'string' for key '%s'", key) < 0)
Expand All @@ -674,7 +673,7 @@ make_json_map_string_string (json_t *src, const struct parser_context *ctx,
return NULL;
}

str = json_string_value(value);
const char *str = json_string_value(value);

ret->values[i] = strdup (str ? str : "");
if (ret->values[i] == NULL)
Expand Down Expand Up @@ -870,11 +869,9 @@ jansson_object_keys_values *json_object_to_keys_values(json_t *object) {
* Input: json_t, const char **
* Ouput: jsont_t
*/
json_t *copy_unmatched_fields(json_t *src, const char **exclude_keys) {
json_t *copy_unmatched_fields(json_t *src, const char **exclude_keys, int len) {
json_t *dst = json_object();

int len = sizeof(exclude_keys) / sizeof(exclude_keys[0]);

const char *key;
json_t *value;

Expand Down
2 changes: 1 addition & 1 deletion src/ocispec/json_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ typedef struct

jansson_object_keys_values *json_object_to_keys_values(json_t *object);

json_t *copy_unmatched_fields(json_t *src, const char **exclude_keys);
json_t *copy_unmatched_fields(json_t *src, const char **exclude_keys, int len);

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion src/ocispec/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,10 @@ def parse_obj_arr_obj(obj, c_file, prefix, obj_typename):
return NULL;
}
"""
f"int len = {len(obj.children)};\n"
f"const char *excluded[] = {'{'}{condition}{'}'};"
"""
json_t *resi = copy_unmatched_fields(tree, excluded);
json_t *resi = copy_unmatched_fields(tree, excluded, len);
size_t resilen = json_object_size(resi);
Expand Down

0 comments on commit 544a0ed

Please sign in to comment.