From: Date: Sat, 15 Nov 2008 16:15:43 +0000 (-0500) Subject: Fix to make sure we do not copy an element on top of itself. X-Git-Tag: 0.25~7 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=809d0d1445516e1b9d04731216df251f05e55c00;p=awesomized%2Flibmemcached Fix to make sure we do not copy an element on top of itself. --- 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++; } }