From: Olivier Matz Date: Thu, 15 Nov 2018 19:21:48 +0000 (+0100) Subject: simplify config list to node table X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=5d3ebfb288bcf56c06e68a1b3ce9dd0b9c6652a5;p=protos%2Flibecoli.git simplify config list to node table --- diff --git a/libecoli/ecoli_node_helper.c b/libecoli/ecoli_node_helper.c index 9ec7e89..94811f2 100644 --- a/libecoli/ecoli_node_helper.c +++ b/libecoli/ecoli_node_helper.c @@ -19,7 +19,7 @@ ec_node_config_node_list_to_table(const struct ec_config *config, { struct ec_node **table = NULL; struct ec_config *child; - size_t n, i; + ssize_t n, i; *len = 0; @@ -33,21 +33,20 @@ ec_node_config_node_list_to_table(const struct ec_config *config, return NULL; } - n = 0; - TAILQ_FOREACH(child, &config->list, next) { - if (ec_config_get_type(child) != EC_CONFIG_TYPE_NODE) { - errno = EINVAL; - return NULL; - } - n++; - } + n = ec_config_count(config); + if (n < 0) + return NULL; - table = ec_malloc(n * sizeof(*table)); + table = ec_calloc(n, sizeof(*table)); if (table == NULL) goto fail; n = 0; TAILQ_FOREACH(child, &config->list, next) { + if (ec_config_get_type(child) != EC_CONFIG_TYPE_NODE) { + errno = EINVAL; + goto fail; + } table[n] = ec_node_clone(child->node); n++; }