Browse Source

vector: fix conflict between index and size in swap_remove

Undefined behaviour and warnings can happen when calling
vlc_vector_swap_remove with the array size as parameter, so as to
remove the last item for example.

Signed-off-by: Thomas Guillem <thomas@gllm.fr>
pull/94/head
Alexandre Janniaux 7 years ago
committed by Thomas Guillem
parent
commit
5b8f1a76b7
  1. 5
      include/vlc_vector.h

5
include/vlc_vector.h

@ -591,7 +591,10 @@ vlc_vector_move_(char *array, size_t index, size_t count, size_t target)
* \param index the index of item to remove
*/
#define vlc_vector_swap_remove(pv, index) \
(pv)->data[index] = (pv)->data[--(pv)->size]
do { \
(pv)->data[index] = (pv)->data[(pv)->size-1]; \
(pv)->size--; \
} while(0)
/**
* Return the index of an item.

Loading…
Cancel
Save