aboutsummaryrefslogtreecommitdiff
path: root/src/rps/gnunet-service-rps_view.c
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-11-30 23:39:02 +0000
committerJulius Bünger <buenger@mytum.de>2015-11-30 23:39:02 +0000
commit27a0b4b9a7e0f80620ba8844a462da49a2928703 (patch)
tree8e2ceb8f10f0f59df1e4612a3f2a81481662d118 /src/rps/gnunet-service-rps_view.c
parent982d8feb72c94b61e11b098a3f4c6ecaf086db3d (diff)
downloadgnunet-27a0b4b9a7e0f80620ba8844a462da49a2928703.tar.gz
gnunet-27a0b4b9a7e0f80620ba8844a462da49a2928703.zip
-fixed bug in removal of peer in "view"
Signed-off-by: Julius Bünger <buenger@mytum.de>
Diffstat (limited to 'src/rps/gnunet-service-rps_view.c')
-rw-r--r--src/rps/gnunet-service-rps_view.c14
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 1dacff26e..b7a0ba287 100644
--- a/src/rps/gnunet-service-rps_view.c
+++ b/src/rps/gnunet-service-rps_view.c
@@ -177,7 +177,8 @@ int
177View_remove_peer (const struct GNUNET_PeerIdentity *peer) 177View_remove_peer (const struct GNUNET_PeerIdentity *peer)
178{ 178{
179 uint32_t *index; 179 uint32_t *index;
180 uint32_t *index_swap; 180 uint32_t *swap_index;
181 uint32_t last_index;
181 182
182 if (GNUNET_NO == View_contains_peer (peer)) 183 if (GNUNET_NO == View_contains_peer (peer))
183 { 184 {
@@ -185,11 +186,14 @@ View_remove_peer (const struct GNUNET_PeerIdentity *peer)
185 } 186 }
186 index = GNUNET_CONTAINER_multipeermap_get (mpm, peer); 187 index = GNUNET_CONTAINER_multipeermap_get (mpm, peer);
187 GNUNET_assert (NULL != index); 188 GNUNET_assert (NULL != index);
188 if (*index < (View_size () - 1) ) 189 last_index = View_size () - 1;
190 if (*index < last_index)
189 { /* Fill the 'gap' in the array with the last peer */ 191 { /* Fill the 'gap' in the array with the last peer */
190 array[*index] = array[(View_size () - 1)]; 192 array[*index] = array[last_index];
191 index_swap = GNUNET_CONTAINER_multipeermap_get (mpm, &array[View_size ()]); 193 GNUNET_assert (GNUNET_YES == View_contains_peer (&array[last_index]));
192 *index_swap = *index; 194 swap_index = GNUNET_CONTAINER_multipeermap_get (mpm, &array[last_index]);
195 GNUNET_assert (NULL != swap_index);
196 *swap_index = *index;
193 GNUNET_free (index); 197 GNUNET_free (index);
194 } 198 }
195 GNUNET_CONTAINER_multipeermap_remove_all (mpm, peer); 199 GNUNET_CONTAINER_multipeermap_remove_all (mpm, peer);