From 099ae042fda3ce9faa22390dbef80179388c0bb0 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 26 Dec 2011 23:52:02 -0800 Subject: [PATCH] Update touch for batching. --- libmemcached/touch.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libmemcached/touch.cc b/libmemcached/touch.cc index 1107139d..ab1f7023 100644 --- a/libmemcached/touch.cc +++ b/libmemcached/touch.cc @@ -42,15 +42,20 @@ static memcached_return_t ascii_touch(memcached_server_write_instance_st instanc const char *key, size_t key_length, time_t expiration) { - char buffer[21]; + char expiration_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1]; + int expiration_buffer_length= snprintf(expiration_buffer, sizeof(expiration_buffer), " %llu", (unsigned long long)expiration); + if (size_t(expiration_buffer_length) >= sizeof(expiration_buffer) or expiration_buffer_length < 0) + { + return memcached_set_error(*instance, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT, + memcached_literal_param("snprintf(MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH)")); + } - int buffer_length= snprintf(buffer, sizeof(buffer), " %u", uint32_t(expiration)); struct libmemcached_io_vector_st vector[]= { { memcached_literal_param("touch ") }, { memcached_array_string(instance->root->_namespace), memcached_array_size(instance->root->_namespace) }, { key, key_length }, - { buffer, buffer_length }, + { expiration_buffer, expiration_buffer_length }, { memcached_literal_param("\r\n") } }; @@ -137,7 +142,7 @@ memcached_return_t memcached_touch_by_key(memcached_st *ptr, } char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - rc= memcached_read_one_response(instance, buffer, sizeof(buffer), NULL); + rc= memcached_response(instance, buffer, sizeof(buffer), NULL); if (rc == MEMCACHED_SUCCESS or rc == MEMCACHED_NOTFOUND) { -- 2.30.2