From 294cf15fd5b1b57c31901327a2ce62a6444ece4f Mon Sep 17 00:00:00 2001 From: Evan Klitzke Date: Tue, 13 Jan 2015 00:38:16 +0000 Subject: [PATCH] directly use the return value of statsrelay_list_expand --- src/hashring.c | 5 +++-- src/list.c | 2 +- src/list.h | 2 +- src/yaml_config.c | 5 +++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/hashring.c b/src/hashring.c index c15bcc7..9189a7c 100644 --- a/src/hashring.c +++ b/src/hashring.c @@ -63,13 +63,14 @@ bool hashring_add(hashring_t ring, const char *line) { } // grow the list - if (statsrelay_list_expand(ring->backends) == NULL) { + void **new_obj = statsrelay_list_expand(ring->backends); + if (new_obj == NULL) { stats_error_log("hashring: failed to expand list"); ring->dealloc(obj); goto add_err; } - ring->backends->data[ring->backends->size - 1] = obj; + *new_obj = obj; return true; add_err: diff --git a/src/list.c b/src/list.c index a4061a5..3fdc651 100644 --- a/src/list.c +++ b/src/list.c @@ -14,7 +14,7 @@ list_t statsrelay_list_new() { return list; } -void* statsrelay_list_expand(list_t list) { +void** statsrelay_list_expand(list_t list) { size_t index = list->size; list->size++; diff --git a/src/list.h b/src/list.h index 9c6c5e9..afc040a 100644 --- a/src/list.h +++ b/src/list.h @@ -16,7 +16,7 @@ list_t statsrelay_list_new(); // get the address for a new item in the list, and ensure its size is // expanded -void *statsrelay_list_expand(list_t list); +void **statsrelay_list_expand(list_t list); // deallocate the list void statsrelay_list_destroy(list_t list); diff --git a/src/yaml_config.c b/src/yaml_config.c index f2796b2..f6ce42c 100644 --- a/src/yaml_config.c +++ b/src/yaml_config.c @@ -188,11 +188,12 @@ struct config* parse_config(FILE *input) { goto parse_err; } } else { - if (statsrelay_list_expand(protoc->ring) == NULL) { + char **data_ptr = (char **) statsrelay_list_expand(protoc->ring); + if (data_ptr == NULL) { stats_error_log("unable to expand list"); goto parse_err; } - if ((protoc->ring->data[protoc->ring->size - 1] = strdup(strval)) == NULL) { + if ((*data_ptr = strdup(strval)) == NULL) { stats_error_log("failed to copy string"); goto parse_err; }