X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fstring.cc;h=c7a47827decfae6ba6e0392c762864cc3ac86b55;hb=1857b8b7b9c015f917a05e2e1f75c31253855c90;hp=0e17484055c5e6356073b4458a07d1ce426f4cf1;hpb=d8dedbd561c7cb57daf4192fe57ce5e205bcadd7;p=m6w6%2Flibmemcached diff --git a/libmemcached/string.cc b/libmemcached/string.cc index 0e174840..c7a47827 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -37,29 +37,29 @@ #include -#include inline static memcached_return_t _string_check(memcached_string_st *string, size_t need) { 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; /* This is the block multiplier. To keep it larger and surive division errors we must round it up */ - adjust= (need - (size_t)(string->current_size - (size_t)(string->end - string->string))) / MEMCACHED_BLOCK_SIZE; + size_t adjust= (need - (size_t)(string->current_size - (size_t)(string->end - string->string))) / MEMCACHED_BLOCK_SIZE; adjust++; - new_size= sizeof(char) * (size_t)((adjust * MEMCACHED_BLOCK_SIZE) + string->current_size); + size_t new_size= sizeof(char) * (size_t)((adjust * MEMCACHED_BLOCK_SIZE) + string->current_size); /* Test for overflow */ if (new_size < need) - return memcached_set_error(*string->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + { + char error_message[1024]; + int error_message_length= snprintf(error_message, sizeof(error_message),"Needed %ld, got %ld", (long)need, (long)new_size); + return memcached_set_error(*string->root, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, error_message, error_message_length); + } - new_value= static_cast(libmemcached_realloc(string->root, string->string, new_size)); + 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); } @@ -92,7 +92,7 @@ memcached_string_st *memcached_string_create(memcached_st *memc, memcached_strin } else { - self= static_cast(libmemcached_malloc(memc, sizeof(memcached_string_st))); + self= libmemcached_xmalloc(memc, memcached_string_st); if (self == NULL) { @@ -192,7 +192,9 @@ memcached_return_t memcached_string_reset(memcached_string_st *string) void memcached_string_free(memcached_string_st *ptr) { if (not ptr) + { return; + } if (ptr->string) { @@ -216,7 +218,7 @@ memcached_return_t memcached_string_check(memcached_string_st *string, size_t ne size_t memcached_string_length(const memcached_string_st *self) { - return (size_t)(self->end - self->string); + return size_t(self->end -self->string); } size_t memcached_string_size(const memcached_string_st *self) @@ -231,7 +233,7 @@ const char *memcached_string_value(const memcached_string_st *self) char *memcached_string_take_value(memcached_string_st *self) { - assert(self); + assert_msg(self, "Invalid memcached_string_st"); // If we fail at adding the null, we copy and move on if (memcached_success(memcached_string_append_null(self))) {