X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fstring.cc;h=c7a47827decfae6ba6e0392c762864cc3ac86b55;hb=3337fe07860804ea2654aa53e9ecdf9470434016;hp=d482d4cd4d21630feac0412b5d927ffcb8645a01;hpb=7b7b8c93445a962375b17f1b22d1fb1b1f693484;p=m6w6%2Flibmemcached diff --git a/libmemcached/string.cc b/libmemcached/string.cc index d482d4cd..c7a47827 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -43,22 +43,23 @@ 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; /* 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); } @@ -91,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) {