libmpm

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

commit f3fe45f2a523b9828f0ed80d6b316c6431f5412a
parent 13da9263b005aa3fde4bfeaffe68e248af9830fa
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 16 May 2017 18:23:23 +0200

Fix(Packer): Add skip on NULL value in JSON; Fix(Compile): Add better checks via safe macros, and now changing state in functions

Diffstat:
Minc/packer.h | 6++++++
Msrc/compile.c | 12++++++++----
Msrc/packer.c | 14++++++--------
3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/inc/packer.h b/inc/packer.h @@ -56,6 +56,12 @@ typedef enum packer_type_e { # define PACKER_CONF_COMP_INST_TOKEN "install" # define PACKER_CONF_DEPS_TOKEN "dependencies" +# define JSON_SKIP_NULL(obj, it) if (json_object_get_type(obj) == json_type_null) \ + { \ + json_object_iter_next(&(it)); \ + continue; \ + } \ + typedef struct packer_header_package_s { char *name; /*!< Name of the package */ char *version; /*!< Version of the package */ diff --git a/src/compile.c b/src/compile.c @@ -46,16 +46,20 @@ bool package_install_cleanup(compile_t *ctx) { bool configure_package(compile_t *ctx) { /* Nothing to configure, we're good */ - if (ctx->package->header->compilation->configure == NULL) - return true; + if (STR_NULL_OR_EMPTY(ctx->package->header->compilation->configure)) + goto end; +end: + ctx->state = INST_STATE_CONFIGURATION; return true; } bool make_package(compile_t *ctx) { /* Nothing to compile, we're good */ - if (ctx->package->header->compilation->make == NULL) - return true; + if (STR_NULL_OR_EMPTY(ctx->package->header->compilation->make)) + goto end; +end: + ctx->state = INST_STATE_COMPILATION; return true; } diff --git a/src/packer.c b/src/packer.c @@ -210,13 +210,10 @@ MPX_STATIC bool packer_read_config_comp(packer_t *ctx, struct json_object *obj) { name = json_object_iter_peek_name(&it); tmp = json_object_iter_peek_value(&it); + + JSON_SKIP_NULL(tmp, it); if (strcmp(name, PACKER_CONF_COMP_CONF_TOKEN) == 0) { - if (json_object_get_type(tmp) == json_type_null) - { - json_object_iter_next(&it); - continue ; - } if (json_object_get_type(tmp) != json_type_array) goto cleanup; @@ -467,9 +464,9 @@ MPX_STATIC void write_package_header(FILE *fd, packer_t *ctx) { fprintf(fd, "%s%c", opt->value, 0); } } - fprintf(fd, "%s%c", h->compilation->make, 0); - fprintf(fd, "%s%c", h->compilation->test, 0); - fprintf(fd, "%s%c", h->compilation->install, 0); + fprintf(fd, "%s%c", STR_OR_EMPTY(h->compilation->make), 0); + fprintf(fd, "%s%c", STR_OR_EMPTY(h->compilation->test), 0); + fprintf(fd, "%s%c", STR_OR_EMPTY(h->compilation->install), 0); list_len = htonl(list_size(h->dependencies->list)); fwrite(&list_len, sizeof(u32_t), 1, fd); @@ -655,6 +652,7 @@ MPX_STATIC int read_package_header_compilation(char *file, packer_t *ctx) comp->make = strdup(file + ret); if (comp->make == NULL) goto cleanup; + ret += strlen(comp->make) + 1; comp->test = strdup(file + ret);