[vlc-devel] [PATCH] vector: fix conflict between index and size in swap_remove

Steve Lhomme robux4 at ycbcr.xyz
Sat Aug 31 10:08:05 CEST 2019


LGTM

On 2019-08-30 16:42, Alexandre Janniaux wrote:
> 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.
> ---
>   include/vlc_vector.h | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/include/vlc_vector.h b/include/vlc_vector.h
> index 76fc2822fd..515e7a4035 100644
> --- a/include/vlc_vector.h
> +++ b/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.
> --
> 2.23.0
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list