X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fstring.cc;h=c7a47827decfae6ba6e0392c762864cc3ac86b55;hb=2b1d1f93e41229a47fff8362fb70012bc2cff9d3;hp=75641ccdd0e47796fbd89e536301aeffd96eb447;hpb=f34725871a4ad46ea3b3194d829eebf81cc5c08e;p=m6w6%2Flibmemcached diff --git a/libmemcached/string.cc b/libmemcached/string.cc index 75641ccd..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, 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); }