1
0
Fork 0

correctly handle empty list of replication servers

yamux
jmjatlanta 2017-07-31 08:50:20 -05:00
parent d969f48324
commit 9bceade4d8
1 changed files with 14 additions and 16 deletions

View File

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