[vlc-devel] [PATCH 1/1] lib: media_track: do not assert on empty tracklist in libvlc_media_tracklist_at

Romain Vimont rom1v at videolabs.io
Wed Apr 21 07:12:31 UTC 2021


On Wed, Apr 21, 2021 at 01:18:21PM +0700, Martin Finkel wrote:
> From: Martin Finkel <martin at videolabs.io>
> 
> ---
>  lib/media_track.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/lib/media_track.c b/lib/media_track.c
> index a11c2973c6..bc6f30dd98 100644
> --- a/lib/media_track.c
> +++ b/lib/media_track.c
> @@ -286,6 +286,9 @@ libvlc_media_tracklist_count( const libvlc_media_tracklist_t *list )
>  libvlc_media_track_t *
>  libvlc_media_tracklist_at( libvlc_media_tracklist_t *list, size_t idx )
>  {
> +    if( list == NULL || list->count == 0 )
> +        return NULL;

This is an error to call this function if list is NULL or if idx is not
in its valid range (including the case where the list is empty), so the
assert should be triggered.

The caller may check the valid range with libvlc_media_tracklist_count()
if necessary before calling this function.

Regards

> +
>      assert( idx < list->count );
>      return &list->tracks[idx]->t;
>  }
> -- 
> 2.20.1
> 
> _______________________________________________
> 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