X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=libecoli%2Fecoli_node_helper.c;h=94811f23ca9041b94e7133a51f64d87643b74cc9;hb=5d3ebfb288bcf56c06e68a1b3ce9dd0b9c6652a5;hp=9ec7e892e65092f88880143a9e4e8942875010c7;hpb=45969caad2bbc2f0adb381c77d47e36c6ae5493c;p=protos%2Flibecoli.git 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++; }