libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit 913c928f2cbf08b08d2418a43e74721cfd8cec55
parent f3199950739b2942848ed55372309270590b7354
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Thu,  6 Apr 2017 17:41:20 +0200

Fix(Packer): Fix a wrong iteration on json array

Diffstat:
Msrc/packer.c | 12+++++-------
Mtests/packer/right/package.json | 3++-
2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/packer.c b/src/packer.c @@ -199,7 +199,7 @@ static bool packer_read_config_comp(packer_t *ctx, struct json_object *obj) { it = json_object_iter_begin(obj); it_end = json_object_iter_end(obj); ctx->header->compilation = packer_header_comp_init(); - while (!json_object_iter_equal(&it, &it_end)) + while (!json_object_iter_equal(&it, &it_end)) { name = json_object_iter_peek_name(&it); tmp = json_object_iter_peek_value(&it); @@ -275,8 +275,8 @@ cleanup: } static bool packer_read_config_deps(packer_t *ctx, struct json_object *obj) { - struct json_object_iterator it, it_end; - struct json_object *tmp; + struct json_object *tmp; + size_t len = 0, i = 0; assert(ctx != NULL); @@ -284,12 +284,10 @@ static bool packer_read_config_deps(packer_t *ctx, struct json_object *obj) { if (obj == NULL || json_object_get_type(obj) != json_type_array) return false; - it = json_object_iter_begin(obj); - it_end = json_object_iter_end(obj); ctx->header->dependencies = packer_header_deps_init(); - while (!json_object_iter_equal(&it, &it_end)) + for (len = json_object_array_length(obj), i = 0; i < len; i++) { - tmp = json_object_iter_peek_value(&it); + tmp = json_object_array_get_idx(obj, i); if (json_object_get_type(tmp) != json_type_string) goto cleanup; list_add(ctx->header->dependencies->list, (char *)json_object_get_string(tmp), diff --git a/tests/packer/right/package.json b/tests/packer/right/package.json @@ -18,6 +18,7 @@ "install": "" }, "dependencies": [ - "something-5.5" + "something-5.5", + "yrdy" ] }