X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libmemcached%2Fflush.c;h=8da6b5b57b10cc663689db00b2a24f4051c0839f;hb=b048aacba5d279f3271163cfaa0704684beca1e2;hp=425d4576b8abeae82685d9b4f9b2b4ac90e970ca;hpb=26c65ac524f21cd73a79f3caf45cdb76c9a41bc0;p=awesomized%2Flibmemcached diff --git a/libmemcached/flush.c b/libmemcached/flush.c index 425d4576..8da6b5b5 100644 --- a/libmemcached/flush.c +++ b/libmemcached/flush.c @@ -8,6 +8,10 @@ static memcached_return_t memcached_flush_textual(memcached_st *ptr, memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration) { memcached_return_t rc; + if ((rc= initialize_query(ptr)) != MEMCACHED_SUCCESS) + { + return rc; + } LIBMEMCACHED_MEMCACHED_FLUSH_START(); if (ptr->flags.binary_protocol) @@ -21,29 +25,37 @@ memcached_return_t memcached_flush(memcached_st *ptr, time_t expiration) static memcached_return_t memcached_flush_textual(memcached_st *ptr, time_t expiration) { - unsigned int x; - size_t send_length; - memcached_return_t rc; - char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; - unlikely (memcached_server_count(ptr) == 0) return MEMCACHED_NO_SERVERS; - for (x= 0; x < memcached_server_count(ptr); x++) + for (unsigned int x= 0; x < memcached_server_count(ptr); x++) { + memcached_return_t rc; + char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE]; + bool no_reply= ptr->flags.no_reply; memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, x); + int send_length; if (expiration) - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "flush_all %llu%s\r\n", - (unsigned long long)expiration, no_reply ? " noreply" : ""); + { + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "flush_all %llu%s\r\n", + (unsigned long long)expiration, no_reply ? " noreply" : ""); + } else - send_length= (size_t) snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, - "flush_all%s\r\n", no_reply ? " noreply" : ""); + { + send_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, + "flush_all%s\r\n", no_reply ? " noreply" : ""); + } + + if (send_length >= MEMCACHED_DEFAULT_COMMAND_SIZE || send_length < 0) + { + return MEMCACHED_FAILURE; + } - rc= memcached_do(instance, buffer, send_length, true); + rc= memcached_do(instance, buffer, (size_t)send_length, true); if (rc == MEMCACHED_SUCCESS && !no_reply) (void)memcached_response(instance, buffer, MEMCACHED_DEFAULT_COMMAND_SIZE, NULL);