diff options
Diffstat (limited to 'src/rps/gnunet-service-rps_view.c')
-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 1dacff26e..b7a0ba287 100644 --- a/src/rps/gnunet-service-rps_view.c +++ b/src/rps/gnunet-service-rps_view.c | |||
@@ -177,7 +177,8 @@ int | |||
177 | View_remove_peer (const struct GNUNET_PeerIdentity *peer) | 177 | View_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); |