From f5838944c3424afa14765d709a127c943f1cf87b Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Wed, 30 Nov 2011 08:41:29 -0800 Subject: [PATCH] Fix usage for using the macro for realloc. --- libmemcached/hosts.cc | 11 +++-------- libmemcached/sasl.cc | 4 ++-- libmemcached/stats.cc | 2 +- libmemcached/string.cc | 5 ++--- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index cb0e3f30..ac6b03ad 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -184,9 +184,7 @@ static memcached_return_t update_continuum(memcached_st *ptr) { memcached_continuum_item_st *new_ptr; - new_ptr= static_cast(libmemcached_realloc(ptr, ptr->ketama.continuum, - (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server, - sizeof(memcached_continuum_item_st))); + new_ptr= libmemcached_xrealloc(ptr, ptr->ketama.continuum, (live_servers + MEMCACHED_CONTINUUM_ADDITION) * points_per_server, memcached_continuum_item_st); if (new_ptr == 0) { @@ -354,9 +352,7 @@ static memcached_return_t server_add(memcached_st *ptr, { assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); - memcached_server_st *new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), - (ptr->number_of_hosts + 1), - sizeof(memcached_server_st))); + memcached_server_st *new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (ptr->number_of_hosts + 1), memcached_server_st); if (new_host_list == NULL) { @@ -398,8 +394,7 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv uint32_t count= memcached_server_list_count(list); memcached_server_st *new_host_list; - new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), - (count + memcached_server_count(ptr)), sizeof(memcached_server_st))); + new_host_list= libmemcached_xrealloc(ptr, memcached_server_list(ptr), (count + memcached_server_count(ptr)), memcached_server_st); if (new_host_list == NULL) { diff --git a/libmemcached/sasl.cc b/libmemcached/sasl.cc index 32906cc8..2e9bdc63 100644 --- a/libmemcached/sasl.cc +++ b/libmemcached/sasl.cc @@ -321,7 +321,7 @@ memcached_return_t memcached_set_sasl_auth_data(memcached_st *ptr, memcached_destroy_sasl_auth_data(ptr); - sasl_callback_t *callbacks= (sasl_callback_t*)libmemcached_calloc(ptr, 4, sizeof(sasl_callback_t)); + sasl_callback_t *callbacks= libmemcached_xcalloc(ptr, 4, sasl_callback_t); size_t password_length= strlen(password); size_t username_length= strlen(username); char *name= (char *)libmemcached_malloc(ptr, username_length +1); @@ -441,7 +441,7 @@ memcached_return_t memcached_clone_sasl(memcached_st *clone, const memcached_st ++total; } - sasl_callback_t *callbacks= (sasl_callback_t*)libmemcached_calloc(clone, total +1, sizeof(sasl_callback_t)); + sasl_callback_t *callbacks= libmemcached_xcalloc(clone, total +1, sasl_callback_t); if (callbacks == NULL) { return MEMCACHED_MEMORY_ALLOCATION_FAILURE; diff --git a/libmemcached/stats.cc b/libmemcached/stats.cc index 78fed03d..239c789d 100644 --- a/libmemcached/stats.cc +++ b/libmemcached/stats.cc @@ -486,7 +486,7 @@ memcached_stat_st *memcached_stat(memcached_st *self, char *args, memcached_retu return NULL; } - memcached_stat_st *stats= static_cast(libmemcached_calloc(self, memcached_server_count(self), sizeof(memcached_stat_st))); + memcached_stat_st *stats= libmemcached_xcalloc(self, memcached_server_count(self), memcached_stat_st); if (not stats) { diff --git a/libmemcached/string.cc b/libmemcached/string.cc index 75641ccd..a94d4421 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -43,7 +43,6 @@ inline static memcached_return_t _string_check(memcached_string_st *string, size if (need && need > (size_t)(string->current_size - (size_t)(string->end - string->string))) { size_t current_offset= (size_t) (string->end - string->string); - char *new_value; size_t adjust; size_t new_size; @@ -56,9 +55,9 @@ inline static memcached_return_t _string_check(memcached_string_st *string, size if (new_size < need) return memcached_set_error(*string->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); - new_value= static_cast(libmemcached_realloc(string->root, string->string, new_size, sizeof(char))); + char *new_value= libmemcached_xrealloc(string->root, string->string, new_size, char); - if (not new_value) + if (new_value == NULL) { return memcached_set_error(*string->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } -- 2.30.2