correctly handle empty list of replication servers

This commit is contained in:
jmjatlanta 2017-07-31 08:50:20 -05:00
parent d969f48324
commit 9bceade4d8

View file

@ -481,22 +481,20 @@ int fs_repo_open_config(struct FSRepo* repo) {
// nodes list
int nodes_pos = _find_token(data, tokens, num_tokens, curr_pos, "Nodes");
if (nodes_pos >= 0) {
if (tokens[nodes_pos].type != JSMN_ARRAY) {
free(data);
return 0;
}
int nodes_size = tokens[nodes_pos].size;
repo->config->replication->nodes = libp2p_utils_vector_new(nodes_size);
nodes_pos++;
for(int i = 0; i < nodes_size; i++) {
char* val = NULL;
if (!_get_json_string_value(data, tokens, num_tokens, nodes_pos + i, NULL, &val))
break;
struct MultiAddress* cur = multiaddress_new_from_string(val);
if (cur == NULL)
continue;
libp2p_utils_vector_add(repo->config->replication->nodes, cur);
free(val);
if (tokens[nodes_pos].type == JSMN_ARRAY) {
int nodes_size = tokens[nodes_pos].size;
repo->config->replication->nodes = libp2p_utils_vector_new(nodes_size);
nodes_pos++;
for(int i = 0; i < nodes_size; i++) {
char* val = NULL;
if (!_get_json_string_value(data, tokens, num_tokens, nodes_pos + i, NULL, &val))
break;
struct MultiAddress* cur = multiaddress_new_from_string(val);
if (cur == NULL)
continue;
libp2p_utils_vector_add(repo->config->replication->nodes, cur);
free(val);
}
}
}
}