servers and you try to set/get values.
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
unsigned int server_key;
+ if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ return MEMCACHED_NO_SERVERS;
+
server_key= memcached_generate_hash(ptr, key, key_length);
if ((rc= memcached_connect(ptr, server_key)) != MEMCACHED_SUCCESS)
memcached_return rc= MEMCACHED_NO_SERVERS;
LIBMEMCACHED_MEMCACHED_CONNECT_START();
- if (ptr->connected == ptr->number_of_hosts)
+ if (ptr->connected == ptr->number_of_hosts && ptr->number_of_hosts)
return MEMCACHED_SUCCESS;
- if (!ptr->hosts)
+ if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
return MEMCACHED_NO_SERVERS;
/* We need to clean up the multi startup piece */
LIBMEMCACHED_MEMCACHED_DELETE_START();
+ if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ return MEMCACHED_NO_SERVERS;
+
server_key= memcached_generate_hash(ptr, key, key_length);
if ((rc= memcached_connect(ptr, server_key)) != MEMCACHED_SUCCESS)
rc= memcached_connect(ptr, 0);
+ if (rc == MEMCACHED_NO_SERVERS)
+ return rc;
+
if (rc != MEMCACHED_SUCCESS)
rc= MEMCACHED_SOME_ERRORS;
memcached_string_st *result_buffer;
LIBMEMCACHED_MEMCACHED_GET_START();
+ if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ {
+ *error= MEMCACHED_NO_SERVERS;
+ return NULL;
+ }
+
server_key= memcached_generate_hash(ptr, key, key_length);
result_buffer= &ptr->result_buffer;
if (number_of_keys == 0)
return MEMCACHED_NOTFOUND;
+ if (ptr->number_of_hosts == 0)
+ return MEMCACHED_NO_SERVERS;
+
cursor_key_exec= (char *)malloc(sizeof(char) * ptr->number_of_hosts);
memset(cursor_key_exec, 0, sizeof(char) * ptr->number_of_hosts);
uint64_t hash= 1; /* Just here to remove compile warning */
unsigned int x;
+ WATCHPOINT_ASSERT(ptr->number_of_hosts);
+
switch (ptr->hash)
{
case MEMCACHED_HASH_DEFAULT:
void memcached_quit_server(memcached_st *ptr, unsigned int server_key)
{
+ if (ptr->hosts == NULL ||
+ ptr->number_of_hosts == 0 ||
+ server_key > ptr->number_of_hosts)
+ return;
+
if (ptr->hosts[server_key].fd != -1)
{
if (ptr->flags & MEM_NO_BLOCK && ptr->hosts[server_key].stack_responses)
{
unsigned int x;
- if (ptr->hosts)
+ if (ptr->hosts && ptr->number_of_hosts)
{
for (x= 0; x < ptr->number_of_hosts; x++)
memcached_quit_server(ptr, x);
if (!(ptr->flags & MEM_NO_BLOCK) && ptr->write_buffer_offset != 0)
WATCHPOINT_ASSERT(0);
#endif
+
+ if (ptr->hosts == NULL || ptr->number_of_hosts == 0)
+ return MEMCACHED_NO_SERVERS;
server_key= memcached_generate_hash(ptr, key, key_length);
if (rc != MEMCACHED_SUCCESS)
return rc;
+
write_length= snprintf(buffer, MEMCACHED_DEFAULT_COMMAND_SIZE,
"%s %.*s %x %llu %zu\r\n", storage_op_string(verb),
(int)key_length, key, flags,
return 0;
}
+/* Make sure we behave properly if server list has no values */
+uint8_t user_supplied_bug4(memcached_st *memc)
+{
+ memcached_return rc;
+ char *keys[]= {"fudge", "son", "food"};
+ size_t key_length[]= {5, 3, 4};
+ unsigned int x;
+ uint16_t flags;
+
+ /* Here we free everything before running a bunch of mget tests */
+ {
+ memcached_server_list_free(memc->hosts);
+ memc->hosts= NULL;
+ memc->number_of_hosts= 0;
+ }
+
+ char return_key[MEMCACHED_MAX_KEY];
+ size_t return_key_length;
+ char *return_value;
+ size_t return_value_length;
+
+ /* We need to empty the server before continueing test */
+ rc= memcached_flush(memc, 0);
+ WATCHPOINT_ERROR(rc);
+ assert(rc == MEMCACHED_NO_SERVERS);
+
+ rc= memcached_mget(memc, keys, key_length, 3);
+ assert(rc == MEMCACHED_NO_SERVERS);
+
+ while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
+ &return_value_length, &flags, &rc)) != NULL)
+ {
+ assert(return_value);
+ }
+ assert(!return_value);
+ assert(return_value_length == 0);
+ assert(rc == MEMCACHED_NO_SERVERS);
+
+ WATCHPOINT;
+ for (x= 0; x < 3; x++)
+ {
+ rc= memcached_set(memc, keys[x], key_length[x],
+ keys[x], key_length[x],
+ (time_t)50, (uint16_t)9);
+ assert(rc == MEMCACHED_NO_SERVERS);
+ }
+
+ WATCHPOINT;
+ rc= memcached_mget(memc, keys, key_length, 3);
+ assert(rc == MEMCACHED_NO_SERVERS);
+ WATCHPOINT;
+
+ x= 0;
+ while ((return_value= memcached_fetch(memc, return_key, &return_key_length,
+ &return_value_length, &flags, &rc)))
+ {
+ WATCHPOINT;
+ assert(return_value);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(return_key_length == return_value_length);
+ assert(!memcmp(return_value, return_key, return_value_length));
+ free(return_value);
+ x++;
+ }
+
+ return 0;
+}
+
uint8_t result_static(memcached_st *memc)
{
memcached_result_st result;
{"user_supplied_bug1", 0, user_supplied_bug1 },
{"user_supplied_bug2", 0, user_supplied_bug2 },
{"user_supplied_bug3", 0, user_supplied_bug3 },
+ {"user_supplied_bug4", 0, user_supplied_bug4 },
{0, 0, 0}
};