From 809d0d1445516e1b9d04731216df251f05e55c00 Mon Sep 17 00:00:00 2001 From: Date: Sat, 15 Nov 2008 11:15:43 -0500 Subject: [PATCH] Fix to make sure we do not copy an element on top of itself. --- libmemcached/memcached_hosts.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libmemcached/memcached_hosts.c b/libmemcached/memcached_hosts.c index 79e88701..34bbf689 100644 --- a/libmemcached/memcached_hosts.c +++ b/libmemcached/memcached_hosts.c @@ -361,9 +361,10 @@ memcached_return memcached_server_remove(memcached_server_st *st_ptr) for (x= 0, index= 0; x < ptr->number_of_hosts; x++) { - if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH)!=0 || list[x].port != st_ptr->port) + if (strncmp(list[x].hostname, st_ptr->hostname, MEMCACHED_MAX_HOST_LENGTH) != 0 || list[x].port != st_ptr->port) { - memcpy(list+index, list+x, sizeof(memcached_server_st)); + if (index != x) + memcpy(list+index, list+x, sizeof(memcached_server_st)); index++; } } -- 2.30.2