X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=libmemcached%2Fstring.cc;h=c7a47827decfae6ba6e0392c762864cc3ac86b55;hb=994f46883f309acc0b94b687565fd5a607a4ab34;hp=a94d442111da9abd37e8ed1fbba4cb0373b464a9;hpb=fddf0928bfebaa0ff1535c0973cfabf5e001e72d;p=m6w6%2Flibmemcached diff --git a/libmemcached/string.cc b/libmemcached/string.cc index a94d4421..c7a47827 100644 --- a/libmemcached/string.cc +++ b/libmemcached/string.cc @@ -43,17 +43,19 @@ 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); - 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); + } char *new_value= libmemcached_xrealloc(string->root, string->string, new_size, char);