diff options
author | ch3 <ch3@140774ce-b5e7-0310-ab8b-a85725594a96> | 2015-11-30 23:39:02 +0000 |
---|---|---|
committer | ch3 <ch3@140774ce-b5e7-0310-ab8b-a85725594a96> | 2015-11-30 23:39:02 +0000 |
commit | 554efefa689e0945beadb06a55e650147f15f6ec (patch) | |
tree | 8e2ceb8f10f0f59df1e4612a3f2a81481662d118 | |
parent | fdd7866badf291fd74082513e2b934249a9baea9 (diff) |
-fixed bug in removal of peer in "view"
Signed-off-by: Julius Bünger <buenger@mytum.de>
git-svn-id: https://gnunet.org/svn/gnunet@36705 140774ce-b5e7-0310-ab8b-a85725594a96
-rw-r--r-- | src/rps/gnunet-service-rps_view.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/rps/gnunet-service-rps_view.c b/src/rps/gnunet-service-rps_view.c index 1dacff26e4..b7a0ba2873 100644 --- a/src/rps/gnunet-service-rps_view.c +++ b/src/rps/gnunet-service-rps_view.c @@ -177,7 +177,8 @@ int View_remove_peer (const struct GNUNET_PeerIdentity *peer) { uint32_t *index; - uint32_t *index_swap; + uint32_t *swap_index; + uint32_t last_index; if (GNUNET_NO == View_contains_peer (peer)) { @@ -185,11 +186,14 @@ View_remove_peer (const struct GNUNET_PeerIdentity *peer) } index = GNUNET_CONTAINER_multipeermap_get (mpm, peer); GNUNET_assert (NULL != index); - if (*index < (View_size () - 1) ) + last_index = View_size () - 1; + if (*index < last_index) { /* Fill the 'gap' in the array with the last peer */ - array[*index] = array[(View_size () - 1)]; - index_swap = GNUNET_CONTAINER_multipeermap_get (mpm, &array[View_size ()]); - *index_swap = *index; + array[*index] = array[last_index]; + GNUNET_assert (GNUNET_YES == View_contains_peer (&array[last_index])); + swap_index = GNUNET_CONTAINER_multipeermap_get (mpm, &array[last_index]); + GNUNET_assert (NULL != swap_index); + *swap_index = *index; GNUNET_free (index); } GNUNET_CONTAINER_multipeermap_remove_all (mpm, peer); |