From: Brian Aker Date: Tue, 27 Dec 2011 07:52:02 +0000 (-0800) Subject: Update touch for batching. X-Git-Tag: 1.0.3~3^2~1^2~14 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=099ae042fda3ce9faa22390dbef80179388c0bb0;p=awesomized%2Flibmemcached Update touch for batching. --- 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) {